本文整理汇总了Python中v2ex.picky.Datum.get方法的典型用法代码示例。如果您正苦于以下问题:Python Datum.get方法的具体用法?Python Datum.get怎么用?Python Datum.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类v2ex.picky.Datum
的用法示例。
在下文中一共展示了Datum.get方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from v2ex.picky import Datum [as 别名]
# 或者: from v2ex.picky.Datum import get [as 别名]
def get(self):
self.session = Session()
if CheckAuth(self) is False:
return DoAuth(self, '/twitter')
template_values = {}
twitter_account = Datum.get('twitter_account')
twitter_password = Datum.get('twitter_password')
api = twitter.Api(username=twitter_account, password=twitter_password)
limit = api.GetRateLimit()
template_values['limit'] = limit
lists = api.GetLists()
template_values['lists'] = lists
tweets = None
tweets = memcache.get('twitter_home')
if tweets is None:
try:
tweets = api.GetHomeTimeline(count=100)
except:
api = None
if tweets is not None:
i = 0;
for tweet in tweets:
tweets[i].datetime = datetime.datetime.fromtimestamp(time.mktime(time.strptime(tweet.created_at, '%a %b %d %H:%M:%S +0000 %Y')))
tweets[i].text = api.ConvertMentions(tweet.text)
tweets[i].text = api.ExpandBitly(tweet.text)
i = i + 1
memcache.set('twitter_home', tweets, 120)
template_values['tweets'] = tweets
else:
template_values['tweets'] = tweets
template_values['system_version'] = VERSION
path = os.path.join(os.path.dirname(__file__), 'tpl', 'writer', 'twitter.html')
self.response.out.write(template.render(path, template_values))
示例2: get
# 需要导入模块: from v2ex.picky import Datum [as 别名]
# 或者: from v2ex.picky.Datum import get [as 别名]
def get(self):
site_domain = Datum.get('site_domain')
site_name = Datum.get('site_name')
site_author = Datum.get('site_author')
site_slogan = Datum.get('site_slogan')
site_updated = Datum.get('site_updated')
if site_updated is None:
site_updated = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
feed_url = 'http://' + site_domain + '/set.xml'
template_values = {
'site_domain' : site_domain,
'site_name' : site_name,
'site_author' : site_author,
'site_slogan' : site_slogan,
'feed_url' : feed_url
}
set_name = self.request.get('set')
set_md5 = hashlib.md5(set_name).hexdigest()
set_cache = 'feed_output_' + set_md5
output = memcache.get(set_cache)
if output is None:
articles = db.GqlQuery("SELECT * FROM Article WHERE article_set = :1 ORDER BY created DESC", set_name)
template_values['articles'] = articles
template_values['articles_total'] = articles.count()
template_values['site_updated'] = site_updated
path = os.path.join(os.path.dirname(__file__), 'tpl', 'shared', 'index.xml')
output = template.render(path, template_values)
memcache.set(set_cache, output, 300)
self.response.headers['Content-type'] = 'text/xml; charset=UTF-8'
self.response.out.write(output)
示例3: get
# 需要导入模块: from v2ex.picky import Datum [as 别名]
# 或者: from v2ex.picky.Datum import get [as 别名]
def get(self):
site_domain = Datum.get('site_domain')
site_name = Datum.get('site_name')
site_author = Datum.get('site_author')
site_slogan = Datum.get('site_slogan')
site_analytics = Datum.get('site_analytics')
site_updated = Datum.get('site_updated')
if site_updated is None:
site_updated = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
feed_url = Datum.get('feed_url')
if feed_url is None:
feed_url = '/index.xml'
else:
if len(feed_url) == 0:
feed_url = '/index.xml'
template_values = {
'site_domain' : site_domain,
'site_name' : site_name,
'site_author' : site_author,
'site_slogan' : site_slogan,
'feed_url' : feed_url
}
if site_analytics is not None:
template_values['site_analytics'] = site_analytics
output = memcache.get('tweets_output')
twitter_account = Datum.get('twitter_account')
twitter_password = Datum.get('twitter_password')
api = twitter.Api(username=twitter_account, password=twitter_password)
if output is None:
tweets = memcache.get('tweets')
if tweets is None:
tweets = api.GetUserTimeline(user=twitter_account, count=20)
memcache.add("tweets", tweets, 600)
for tweet in tweets:
tweet.datetime = datetime.datetime.fromtimestamp(time.mktime(time.strptime(tweet.created_at, '%a %b %d %H:%M:%S +0000 %Y')))
tweet.text = api.ConvertMentions(tweet.text)
tweet.text = api.ExpandBitly(tweet.text)
pages = db.GqlQuery("SELECT * FROM Article WHERE is_page = TRUE AND is_for_sidebar = TRUE ORDER BY title ASC")
template_values['page_title'] = site_name + u' › Latest 20 Tweets by @' + twitter_account
template_values['tweets'] = tweets
template_values['tweets_total'] = len(tweets)
template_values['twitter_account'] = tweets[0].user.name;
template_values['twitter_followers'] = tweets[0].user.followers_count;
template_values['twitter_avatar'] = tweets[0].user.profile_image_url
template_values['pages'] = pages
template_values['pages_total'] = pages.count()
template_values['page_top'] = True
site_theme = Datum.get('site_theme')
if site_theme is None:
site_theme = 'default'
themes = os.listdir(os.path.join(os.path.dirname(__file__), 'tpl', 'themes'))
if site_theme not in themes:
site_theme = 'default'
path = os.path.join(os.path.dirname(__file__), 'tpl', 'themes', site_theme, 'tweets.html')
output = template.render(path, template_values)
memcache.add('tweets_output', output, 600)
self.response.out.write(output)
示例4: get
# 需要导入模块: from v2ex.picky import Datum [as 别名]
# 或者: from v2ex.picky.Datum import get [as 别名]
def get(self):
site_domain = Datum.get('site_domain')
site_name = Datum.get('site_name')
try:
google_ping = 'http://blogsearch.google.com/ping?name=' + urllib.quote(Datum.get('site_name')) + '&url=http://' + urllib.quote(Datum.get('site_domain')) + '/&changesURL=http://' + urllib.quote(Datum.get('site_domain')) + '/index.xml'
result = urlfetch.fetch(google_ping)
if result.status_code == 200:
self.response.out.write('OK: Google Blog Search Ping: ' + google_ping)
else:
self.response.out.write('Reached but failed: Google Blog Search Ping: ' + google_ping)
except:
self.response.out.write('Failed: Google Blog Search Ping: ' + google_ping)
示例5: get
# 需要导入模块: from v2ex.picky import Datum [as 别名]
# 或者: from v2ex.picky.Datum import get [as 别名]
def get(self, user):
self.session = Session()
if CheckAuth(self) is False:
return DoAuth(self, '/twitter/user/' + user)
template_values = {}
twitter_account = Datum.get('twitter_account')
twitter_password = Datum.get('twitter_password')
api = twitter.Api(username=twitter_account, password=twitter_password)
try:
limit = api.GetRateLimit()
template_values['limit'] = limit
lists = api.GetLists()
template_values['lists'] = lists
if twitter_account == user:
template_values['me'] = True
else:
template_values['me'] = False
friendships_ab = False
friendships_ba = False
friendships_ab = api.GetFriendshipsExists(twitter_account, user)
friendships_ba = api.GetFriendshipsExists(user, twitter_account)
tweets = None
tweets = memcache.get('twitter_user_' + user)
if tweets is None:
try:
tweets = api.GetUserTimeline(user=user, count=100)
except:
api = None
if tweets is not None:
i = 0;
for tweet in tweets:
tweets[i].datetime = datetime.datetime.fromtimestamp(time.mktime(time.strptime(tweet.created_at, '%a %b %d %H:%M:%S +0000 %Y')))
tweets[i].text = api.ConvertMentions(tweet.text)
tweets[i].text = api.ExpandBitly(tweet.text)
i = i + 1
memcache.set('twitter_user_' + user, tweets, 120)
template_values['tweets'] = tweets
else:
template_values['tweets'] = tweets
template_values['friendships_ab'] = friendships_ab
template_values['friendships_ba'] = friendships_ba
template_values['twitter_user'] = tweets[0].user
template_values['system_version'] = VERSION
template_values['mode_twitter'] = True;
template_values['page_title'] = 'Twitter User'
path = os.path.join(os.path.dirname(__file__), 'tpl', 'writer', 'twitter_user.html')
self.response.out.write(template.render(path, template_values))
except:
template_values['system_version'] = VERSION
template_values['mode_twitter'] = True;
template_values['page_title'] = 'Twitter Fail'
path = os.path.join(os.path.dirname(__file__), 'tpl', 'writer', 'twitter_fail.html')
self.response.out.write(template.render(path, template_values))
示例6: post
# 需要导入模块: from v2ex.picky import Datum [as 别名]
# 或者: from v2ex.picky.Datum import get [as 别名]
def post(self):
site_domain = Datum.get('site_domain')
site_name = Datum.get('site_name')
try:
google_ping = 'http://blogsearch.google.com/ping?name=' + urllib.quote(Datum.get('site_name')) + '&url=http://' + urllib.quote(Datum.get('site_domain')) + '/&changesURL=http://' + urllib.quote(Datum.get('site_domain')) + '/index.xml'
result = urlfetch.fetch(google_ping)
hub_field = {"hub.mode":"publish","hub.url":"http://imimom0.appspot.com/index.xml"}
hub_ping = urlfetch.fetch(url='http://pubsubhubbub.appspot.com/',payload=urllib.urlencode(hub_field),method=urlfetch.POST)
if result.status_code == 200:
self.response.out.write('OK: Google Blog Search Ping: ' + google_ping)
else:
self.response.out.write('Reached but failed: Google Blog Search Ping: ' + google_ping)
except:
self.response.out.write('Failed: Google Blog Search Ping: ' + google_ping)
示例7: post
# 需要导入模块: from v2ex.picky import Datum [as 别名]
# 或者: from v2ex.picky.Datum import get [as 别名]
def post(self):
self.session = Session()
if CheckAuth(self) is False:
return DoAuth(self, '/twitter')
tweet = self.request.get('status')
if tweet != '':
twitter_account = Datum.get('twitter_account')
twitter_password = Datum.get('twitter_password')
api = twitter.Api(username=twitter_account, password=twitter_password)
try:
api.PostUpdate(tweet)
except:
api = None
memcache.delete('twitter_home')
self.redirect('/twitter')
示例8: CheckAuth
# 需要导入模块: from v2ex.picky import Datum [as 别名]
# 或者: from v2ex.picky.Datum import get [as 别名]
def CheckAuth(request):
site_domain = Datum.get('site_domain')
cookies = Cookies(request, max_age = 86400, path = '/')
if 'auth' in cookies:
auth = cookies['auth']
if str(auth) != hashlib.sha1(SECRET + ':' + site_domain).hexdigest():
return False
else:
return True
else:
return False
示例9: CheckAuth
# 需要导入模块: from v2ex.picky import Datum [as 别名]
# 或者: from v2ex.picky.Datum import get [as 别名]
def CheckAuth(request):
site_domain = Datum.get("site_domain")
cookies = Cookies(request, max_age=2678400, path="/")
if "auth" in cookies:
auth = cookies["auth"]
if str(auth) != hashlib.sha1(SECRET + ":" + site_domain).hexdigest():
return False
else:
return True
else:
return False
示例10: get
# 需要导入模块: from v2ex.picky import Datum [as 别名]
# 或者: from v2ex.picky.Datum import get [as 别名]
def get(self):
site_domain = Datum.get("site_domain")
site_name = Datum.get("site_name")
try:
google_ping = (
"http://blogsearch.google.com/ping?name="
+ urllib.quote(Datum.get("site_name"))
+ "&url=http://"
+ urllib.quote(Datum.get("site_domain"))
+ "/&changesURL=http://"
+ urllib.quote(Datum.get("site_domain"))
+ "/index.xml"
)
result = urlfetch.fetch(google_ping)
if result.status_code == 200:
self.response.out.write("OK: Google Blog Search Ping: " + google_ping)
else:
self.response.out.write("Reached but failed: Google Blog Search Ping: " + google_ping)
except:
self.response.out.write("Failed: Google Blog Search Ping: " + google_ping)
示例11: get
# 需要导入模块: from v2ex.picky import Datum [as 别名]
# 或者: from v2ex.picky.Datum import get [as 别名]
def get(self):
self.session = Session()
site_domain = Datum.get('site_domain')
site_domain_sync = Datum.get('site_domain_sync')
site_name = Datum.get('site_name')
site_author = Datum.get('site_author')
site_slogan = Datum.get('site_slogan')
site_analytics = Datum.get('site_analytics')
if site_domain is None:
site_domain = os.environ['HTTP_HOST']
Datum.set('site_domain', os.environ['HTTP_HOST'])
if site_domain_sync is None:
site_domain_sync = os.environ['HTTP_HOST']
Datum.set('site_domain_sync', os.environ['HTTP_HOST'])
template_values = {}
if 'message' in self.session:
message = self.session['message']
del self.session['message']
else:
message = None
template_values['message'] = message
destination = None
destination = self.request.get('destination')
template_values['destination'] = destination
template_values['system_version'] = VERSION
path = os.path.join(os.path.dirname(__file__), 'tpl', 'writer', 'auth.html')
self.response.out.write(template.render(path, template_values))
示例12: post
# 需要导入模块: from v2ex.picky import Datum [as 别名]
# 或者: from v2ex.picky.Datum import get [as 别名]
def post(self):
self.session = Session()
site_domain = Datum.get("site_domain")
site_domain_sync = Datum.get("site_domain_sync")
site_name = Datum.get("site_name")
site_author = Datum.get("site_author")
site_slogan = Datum.get("site_slogan")
site_analytics = Datum.get("site_analytics")
destination = self.request.get("destination")
if str(destination) == "":
destination = None
if site_domain is None:
site_domain = os.environ["HTTP_HOST"]
Datum.set("site_domain", os.environ["HTTP_HOST"])
if site_domain_sync is None:
site_domain_sync = os.environ["HTTP_HOST"]
Datum.set("site_domain_sync", os.environ["HTTP_HOST"])
cookies = Cookies(self, max_age=86400, path="/")
s = self.request.get("secret")
sha1 = hashlib.sha1(s).hexdigest()
if sha1 == SECRET:
cookies["auth"] = hashlib.sha1(SECRET + ":" + site_domain).hexdigest()
if destination is None:
self.redirect("/writer/overview")
else:
self.redirect(str(destination))
else:
self.session["message"] = "Your entered secret passphrase isn't correct"
if destination is None:
self.redirect("/writer/auth")
else:
self.redirect("/writer/auth?destination=" + str(destination))
示例13: TwitterHomeHandler
# 需要导入模块: from v2ex.picky import Datum [as 别名]
# 或者: from v2ex.picky.Datum import get [as 别名]
from v2ex.picky.ext import twitter
from v2ex.picky import Datum
from version import *
from v2ex.picky.security import CheckAuth, DoAuth
from v2ex.picky.ext.sessions import Session
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.api import memcache
from google.appengine.api import users
site_domain = Datum.get('site_domain')
site_name = Datum.get('site_name')
site_author = Datum.get('site_author')
site_slogan = Datum.get('site_slogan')
site_analytics = Datum.get('site_analytics')
MODE_TWITTER = True
class TwitterHomeHandler(webapp.RequestHandler):
def get(self):
self.session = Session()
if CheckAuth(self) is False:
return DoAuth(self, '/twitter')
template_values = {}
api = twitter.new(Datum)
account = api.VerifyCredentials()