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)
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)
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)
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))
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))
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))
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)
def get(self, set): # 将获取的set进行unquote并转换为uncode编码 set_encode = urllib.unquote(set).decode('utf-8') 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 = None #output = memcache.get('ias_output') if output is None: articles = None #articles = memcache.get('ias') if articles is None: articles = db.GqlQuery("SELECT * FROM Article WHERE article_set = :1 ORDER BY created DESC LIMIT 100", set_encode) memcache.add("ias", articles, 7200) pages = db.GqlQuery("SELECT * FROM Article WHERE is_page = TRUE AND is_for_sidebar = TRUE ORDER BY title ASC") if site_name is not None: template_values['page_title'] = site_name + u' › Article Set | ' + set_encode else: template_values['page_title'] = u'Project Picky › Article Set | ' + set_encode template_values['articles'] = articles template_values['article_total'] = articles.count() template_values['pages'] = pages template_values['pages_total'] = pages.count() template_values['page_as'] = 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, 'index.html') output = template.render(path, template_values) memcache.add('ias_output', output, 7200) self.response.out.write(output)
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)
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('archive_output') if output is None: articles = memcache.get('archive') if articles is None: articles = db.GqlQuery( "SELECT * FROM Article WHERE is_page = FALSE ORDER BY created DESC" ) memcache.add("archive", articles, 86400) pages = db.GqlQuery( "SELECT * FROM Article WHERE is_page = TRUE AND is_for_sidebar = TRUE ORDER BY title ASC" ) if site_name is not None: template_values['page_title'] = site_name + u' › Archive' else: template_values['page_title'] = u'Project Picky › Archive' template_values['articles'] = articles template_values['articles_total'] = articles.count() template_values['pages'] = pages template_values['pages_total'] = pages.count() template_values['page_archive'] = 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, 'index.html') output = template.render(path, template_values) memcache.add('archive_output', output, 86400) self.response.out.write(output)
def get(self, method, user): self.session = Session() if CheckAuth(self) is False: return DoAuth(self, '/twitter/user/' + user) twitter_account = Datum.get('twitter_account') if twitter_account == user: self.redirect('/twitter/user/' + user) else: twitter_password = Datum.get('twitter_password') api = twitter.Api(username=twitter_account, password=twitter_password) if method == 'follow': twitter_user = api.CreateFriendship(user) if method == 'unfollow': twitter_user = api.DestroyFriendship(user) self.redirect('/twitter/user/' + user)
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')
def get(self): template_values = { 'site_domain' : Datum.get('site_domain'), } path = os.path.join(os.path.dirname(__file__), 'tpl', 'shared', 'robots.txt') self.response.headers['Content-type'] = 'text/plain; charset=UTF-8' self.response.out.write(template.render(path, template_values))
def get(self): self.session = Session() if CheckAuth(self) is False: return DoAuth(self, '/twitter/inbox') 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 tweets = None tweets = memcache.get('twitter_inbox') if tweets is None: try: tweets = api.GetDirectMessages() 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_inbox', tweets, 120) template_values['tweets'] = tweets else: template_values['tweets'] = tweets template_values['system_version'] = VERSION template_values['mode_twitter'] = True template_values['page_title'] = 'Twitter Inbox' path = os.path.join(os.path.dirname(__file__), 'tpl', 'writer', 'twitter_inbox.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))
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('archive_output') if output is None: articles = memcache.get('archive') if articles is None: articles = db.GqlQuery("SELECT * FROM Article WHERE is_page = FALSE ORDER BY created DESC") memcache.add("archive", articles, 86400) pages = db.GqlQuery("SELECT * FROM Article WHERE is_page = TRUE AND is_for_sidebar = TRUE ORDER BY title ASC") if site_name is not None: template_values['page_title'] = site_name + u' › Archive' else: template_values['page_title'] = u'Project Picky › Archive' template_values['articles'] = articles template_values['articles_total'] = articles.count() template_values['pages'] = pages template_values['pages_total'] = pages.count() template_values['page_archive'] = 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, 'index.html') output = template.render(path, template_values) memcache.add('archive_output', output, 86400) self.response.out.write(output)
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
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)
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
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
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))
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))
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))
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))
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 = 3600, 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))
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('feed_output') if output is None: articles = db.GqlQuery( "SELECT * FROM Article WHERE is_page = FALSE ORDER BY created DESC LIMIT 100" ) 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('feed_output', output, 86400) self.response.headers['Content-type'] = 'text/xml; charset=UTF-8' self.response.out.write(output)
def get(self): self.session = Session() cookies = Cookies(self, max_age=3600, path="/") if "auth" in cookies: del cookies["auth"] 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") template_values = {} template_values["site_name"] = site_name template_values["site_domain"] = site_domain template_values["system_version"] = VERSION path = os.path.join(os.path.dirname(__file__), "tpl", "writer", "signout.html") self.response.out.write(template.render(path, template_values))
def get(self): self.session = Session() cookies = Cookies(self, max_age = 3600, path = '/') if 'auth' in cookies: del cookies['auth'] 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') template_values = {} template_values['site_name'] = site_name template_values['site_domain'] = site_domain template_values['system_version'] = VERSION path = os.path.join(os.path.dirname(__file__), 'tpl', 'writer', 'signout.html') self.response.out.write(template.render(path, template_values))
def get(self, key=''): self.session = Session() if CheckAuth(self) is False: return DoAuth(self, '/writer/new') 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') site_default_format = Datum.get('site_default_format') if 'page' in self.session: page = self.session['page'] else: page = 0 if (key): article = db.get(db.Key(key)) template_values = { 'site_default_format': site_default_format, 'article': article, 'page_mode': 'edit', 'page_title': 'Edit Article', 'page_reminder': reminder.writer_write, 'page': page } else: template_values = { 'site_default_format': site_default_format, 'page_mode': 'new', 'page_title': 'New Article', 'page_reminder': reminder.writer_write, 'page': page } if site_analytics is not None: template_values['site_analytics'] = site_analytics template_values['system_version'] = VERSION path = os.path.join(os.path.dirname(__file__), 'tpl', 'writer', 'write.html') self.response.out.write(template.render(path, template_values))
def get(self, key = ''): self.session = Session() if CheckAuth(self) is False: return DoAuth(self, '/writer/new') 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') site_default_format = Datum.get('site_default_format') if 'page' in self.session: page = self.session['page'] else: page = 0 if (key): article = db.get(db.Key(key)) template_values = { 'site_default_format' : site_default_format, 'article' : article, 'page_mode' : 'edit', 'page_title' : 'Edit Article', 'page_reminder': reminder.writer_write, 'page' : page } else: template_values = { 'site_default_format' : site_default_format, 'page_mode' : 'new', 'page_title' : 'New Article', 'page_reminder': reminder.writer_write, 'page' : page } if site_analytics is not None: template_values['site_analytics'] = site_analytics template_values['system_version'] = VERSION path = os.path.join(os.path.dirname(__file__), 'tpl', 'writer', 'write.html') self.response.out.write(template.render(path, template_values))
def get(self, key=""): self.session = Session() if CheckAuth(self) is False: return DoAuth(self, "/writer/new") 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") site_default_format = Datum.get("site_default_format") if "page" in self.session: page = self.session["page"] else: page = 0 if key: article = db.get(db.Key(key)) template_values = { "site_default_format": site_default_format, "article": article, "page_mode": "edit", "page_title": "Edit Article", "page_reminder": reminder.writer_write, "page": page, } else: template_values = { "site_default_format": site_default_format, "page_mode": "new", "page_title": "New Article", "page_reminder": reminder.writer_write, "page": page, } if site_analytics is not None: template_values["site_analytics"] = site_analytics template_values["system_version"] = VERSION path = os.path.join(os.path.dirname(__file__), "tpl", "writer", "write.html") self.response.out.write(template.render(path, template_values))
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('sitemap_output') if output is None: articles = db.GqlQuery("SELECT * FROM Article ORDER BY last_modified DESC") 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', 'sitemap.xml') output = template.render(path, template_values) memcache.set('sitemap_output', output, 86400) self.response.headers['Content-type'] = 'text/xml; charset=UTF-8' self.response.out.write(output)
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()
def get(self): self.session = Session() if CheckAuth(self) is False: return DoAuth(self, '/writer/overview') 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']) articles = memcache.get('writer_articles') if articles is None: articles = Article.all().order('-created') memcache.set('writer_articles', articles, 86400) paginator = ObjectPaginator(articles, PAGE_SIZE) try: page = int(self.request.get('page', 0)) articles = paginator.get_page(page) except InvalidPage: articles = paginator.get_page(int(paginator.pages - 1)) if paginator.pages > 1: is_paginated = True else: is_paginated = False if site_domain is None or site_name is None or site_author is None: site_configured = False else: site_configured = True if is_paginated: self.session['page'] = page urls = memcache.get('writer_urls') if urls is None: everything = Article.all().order('-title_url') urls = [] for article in everything: urls.append(article.title_url) memcache.set('writer_urls', urls, 86400) template_values = { 'site_configured': site_configured, 'is_paginated': is_paginated, 'page_size': PAGE_SIZE, 'page_has_next': paginator.has_next_page(page), 'page_has_previous': paginator.has_previous_page(page), 'page': page, 'next': page + 1, 'previous': page - 1, 'pages': paginator.pages, 'articles': articles, 'articles_total': len(articles), 'page_range': range(0, paginator.pages), 'urls': urls } if site_analytics is not None: template_values['site_analytics'] = site_analytics if site_domain_sync is None: q = site_domain else: q = site_domain + ' OR ' + site_domain_sync mentions_web = memcache.get('mentions_web') if mentions_web is None: try: mentions_web = feedparser.parse( 'http://blogsearch.google.com/blogsearch_feeds?hl=en&q=' + urllib.quote('link:' + Datum.get('site_domain')) + '&ie=utf-8&num=10&output=atom') memcache.add('mentions_web', mentions_web, 600) except: mentions_web = None if mentions_web is not None: template_values['mentions_web'] = mentions_web.entries mentions_twitter = memcache.get('mentions_twitter') if mentions_twitter is None: try: result = urlfetch.fetch(TWITTER_API_ROOT + 'search.json?q=' + urllib.quote(q)) if result.status_code == 200: mentions_twitter = simplejson.loads(result.content) memcache.add('mentions_twitter', mentions_twitter, 600) except: mentions_twitter = None if mentions_twitter is not None: if len(mentions_twitter['results']) > 0: template_values['mentions_twitter'] = mentions_twitter[ 'results'] template_values['system_version'] = VERSION if 'message' in self.session: template_values['message'] = self.session['message'] del self.session['message'] path = os.path.join(os.path.dirname(__file__), 'tpl', 'writer', 'overview.html') self.response.out.write(template.render(path, template_values))
def get(self): self.session = Session() if CheckAuth(self) is False: return DoAuth(self, '/writer/settings') 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') site_default_format = Datum.get('site_default_format') if site_default_format is None: site_default_format = 'html' twitter_account = Datum.get('twitter_account') twitter_password = Datum.get('twitter_password') twitter_sync = None q = db.GqlQuery("SELECT * FROM Datum WHERE title = 'twitter_sync'") if q.count() == 1: twitter_sync = q[0].substance if (twitter_sync == 'True'): twitter_sync = True else: twitter_sync = False feed_url = Datum.get('feed_url') themes = os.listdir( os.path.join(os.path.dirname(__file__), 'tpl', 'themes')) site_theme = Datum.get('site_theme') template_values = { 'site_domain': site_domain, 'site_domain_sync': site_domain_sync, 'site_name': site_name, 'site_author': site_author, 'site_slogan': site_slogan, 'site_analytics': site_analytics, 'site_default_format': site_default_format, 'twitter_account': twitter_account, 'twitter_password': twitter_password, 'twitter_sync': twitter_sync, 'feed_url': feed_url, 'themes': themes, 'site_theme': site_theme } if site_analytics is not None: template_values['site_analytics'] = site_analytics template_values['system_version'] = VERSION path = os.path.join(os.path.dirname(__file__), 'tpl', 'writer', 'settings.html') self.response.out.write(template.render(path, template_values))
def post(self, key=''): self.session = Session() if CheckAuth(self) is False: return DoAuth(self, '/writer') 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') site_default_format = Datum.get('site_default_format') if 'page' in self.session: page = self.session['page'] else: page = 0 site_default_format = Datum.get('site_default_format') if (self.request.get('content') != ''): if (key): article = db.get(db.Key(key)) article.title = self.request.get('title') article.title_link = self.request.get('title_link') article.title_url = self.request.get('title_url') article.parent_url = self.request.get('parent_url') article.content = self.request.get('content') article.article_set = self.request.get('article_set') article.format = self.request.get('format') if article.format not in CONTENT_FORMATS: article.format = site_default_format if article.format == 'markdown': article.content_formatted = markdown.markdown( article.content) if (self.request.get('is_page') == 'True'): article.is_page = True else: article.is_page = False if (self.request.get('is_for_sidebar') == 'True'): article.is_for_sidebar = True else: article.is_for_sidebar = False article.put() self.session[ 'message'] = '<div style="float: right;"><a href="http://' + site_domain + '/' + article.title_url + '" target="_blank" class="super normal button">View Now</a></div>Changes has been saved into <a href="/writer/edit/' + key + '">' + article.title + '</a>' else: article = Article() article.title = self.request.get('title') article.title_link = self.request.get('title_link') article.title_url = self.request.get('title_url') article.parent_url = self.request.get('parent_url') article.content = self.request.get('content') article.article_set = self.request.get('article_set') article.format = self.request.get('format') if article.format not in CONTENT_FORMATS: article.format = site_default_format if article.format == 'markdown': article.content_formatted = markdown.markdown( article.content) if (self.request.get('is_page') == 'True'): article.is_page = True else: article.is_page = False if (self.request.get('is_for_sidebar') == 'True'): article.is_for_sidebar = True else: article.is_for_sidebar = False article.put() self.session[ 'message'] = '<div style="float: right;"><a href="http://' + site_domain + '/' + article.title_url + '" target="_blank" class="super normal button">View Now</a></div>New article <a href="/writer/edit/' + str( article.key( )) + '">' + article.title + '</a> has been created' # Ping Twitter twitter_sync = Datum.get('twitter_sync') if twitter_sync == 'True' and article.is_page is False: twitter_account = Datum.get('twitter_account') twitter_password = Datum.get('twitter_password') if twitter_account != '' and twitter_password != '': api = twitter.Api(username=twitter_account, password=twitter_password) try: status = api.PostUpdate( article.title + ' http://' + site_domain_sync + '/' + article.title_url + ' (Sync via @projectpicky)') except: api = None obsolete = [ 'archive', 'archive_output', 'feed_output', 'index', 'index_output', 'writer_articles', 'writer_urls' ] memcache.delete_multi(obsolete) Datum.set('site_updated', time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())) # Ping Google Blog Search if site_domain.find('localhost') == -1: 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')) + '/sitemap.xml' result = urlfetch.fetch(google_ping) except: taskqueue.add(url='/writer/ping') self.redirect('/writer/overview?page=' + str(page)) else: article = Article() article.title = self.request.get('title') article.title_link = self.request.get('title_link') article.title_url = self.request.get('title_url') article.content = self.request.get('content') article.article_set = self.request.get('article_set') article.format = self.request.get('format') if article.format not in CONTENT_FORMATS: article.format = site_default_format if (self.request.get('is_page') == 'True'): article.is_page = True else: article.is_page = False if (self.request.get('is_for_sidebar') == 'True'): article.is_for_sidebar = True else: article.is_for_sidebar = False template_values = { 'site_default_format': site_default_format, 'article': article, 'page_mode': 'new', 'page_title': 'New Article', 'page_reminder': reminder.writer_write, 'message': message.content_empty, 'user_email': user.email(), 'page': page } if site_analytics is not None: template_values['site_analytics'] = site_analytics template_values['system_version'] = VERSION path = os.path.join(os.path.dirname(__file__), 'tpl', 'writer', 'write.html') self.response.out.write(template.render(path, template_values))
def post(self, key=""): self.session = Session() if CheckAuth(self) is False: return DoAuth(self, "/writer") 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") site_default_format = Datum.get("site_default_format") if "page" in self.session: page = self.session["page"] else: page = 0 site_default_format = Datum.get("site_default_format") if self.request.get("content") != "": if key: article = db.get(db.Key(key)) article.title = self.request.get("title") article.title_link = self.request.get("title_link") article.title_url = self.request.get("title_url") article.parent_url = self.request.get("parent_url") article.content = self.request.get("content") article.article_set = self.request.get("article_set") article.format = self.request.get("format") if article.format not in CONTENT_FORMATS: article.format = site_default_format if article.format == "markdown": article.content_formatted = markdown.markdown(article.content) if self.request.get("is_page") == "True": article.is_page = True else: article.is_page = False if self.request.get("is_for_sidebar") == "True": article.is_for_sidebar = True else: article.is_for_sidebar = False article.put() self.session["message"] = ( '<div style="float: right;"><a href="http://' + site_domain + "/" + article.title_url + '" target="_blank" class="super normal button">View Now</a></div>Changes has been saved into <a href="/writer/edit/' + key + '">' + article.title + "</a>" ) else: article = Article() article.title = self.request.get("title") article.title_link = self.request.get("title_link") article.title_url = self.request.get("title_url") article.parent_url = self.request.get("parent_url") article.content = self.request.get("content") article.article_set = self.request.get("article_set") article.format = self.request.get("format") if article.format not in CONTENT_FORMATS: article.format = site_default_format if article.format == "markdown": article.content_formatted = markdown.markdown(article.content) if self.request.get("is_page") == "True": article.is_page = True else: article.is_page = False if self.request.get("is_for_sidebar") == "True": article.is_for_sidebar = True else: article.is_for_sidebar = False article.put() self.session["message"] = ( '<div style="float: right;"><a href="http://' + site_domain + "/" + article.title_url + '" target="_blank" class="super normal button">View Now</a></div>New article <a href="/writer/edit/' + str(article.key()) + '">' + article.title + "</a> has been created" ) # Ping Twitter twitter_sync = Datum.get("twitter_sync") if twitter_sync == "True" and article.is_page is False: twitter_account = Datum.get("twitter_account") twitter_password = Datum.get("twitter_password") if twitter_account != "" and twitter_password != "": api = twitter.Api(username=twitter_account, password=twitter_password) try: status = api.PostUpdate( article.title + " http://" + site_domain_sync + "/" + article.title_url + " (Sync via @projectpicky)" ) except: api = None obsolete = [ "archive", "archive_output", "feed_output", "index", "index_output", "writer_articles", "writer_urls", ] memcache.delete_multi(obsolete) Datum.set("site_updated", time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())) # Ping Google Blog Search if site_domain.find("localhost") == -1: 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")) + "/sitemap.xml" ) result = urlfetch.fetch(google_ping) except: taskqueue.add(url="/writer/ping") self.redirect("/writer/overview?page=" + str(page)) else: article = Article() article.title = self.request.get("title") article.title_link = self.request.get("title_link") article.title_url = self.request.get("title_url") article.content = self.request.get("content") article.article_set = self.request.get("article_set") article.format = self.request.get("format") if article.format not in CONTENT_FORMATS: article.format = site_default_format if self.request.get("is_page") == "True": article.is_page = True else: article.is_page = False if self.request.get("is_for_sidebar") == "True": article.is_for_sidebar = True else: article.is_for_sidebar = False template_values = { "site_default_format": site_default_format, "article": article, "page_mode": "new", "page_title": "New Article", "page_reminder": reminder.writer_write, "message": message.content_empty, "user_email": user.email(), "page": page, } if site_analytics is not None: template_values["site_analytics"] = site_analytics template_values["system_version"] = VERSION path = os.path.join(os.path.dirname(__file__), "tpl", "writer", "write.html") self.response.out.write(template.render(path, template_values))
def get(self): self.session = Session() if CheckAuth(self) is False: return DoAuth(self, "/writer/settings") 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") site_default_format = Datum.get("site_default_format") if site_default_format is None: site_default_format = "html" twitter_account = Datum.get("twitter_account") twitter_password = Datum.get("twitter_password") twitter_sync = None q = db.GqlQuery("SELECT * FROM Datum WHERE title = 'twitter_sync'") if q.count() == 1: twitter_sync = q[0].substance if twitter_sync == "True": twitter_sync = True else: twitter_sync = False feed_url = Datum.get("feed_url") themes = os.listdir(os.path.join(os.path.dirname(__file__), "tpl", "themes")) site_theme = Datum.get("site_theme") template_values = { "site_domain": site_domain, "site_domain_sync": site_domain_sync, "site_name": site_name, "site_author": site_author, "site_slogan": site_slogan, "site_analytics": site_analytics, "site_default_format": site_default_format, "twitter_account": twitter_account, "twitter_password": twitter_password, "twitter_sync": twitter_sync, "feed_url": feed_url, "themes": themes, "site_theme": site_theme, } if site_analytics is not None: template_values["site_analytics"] = site_analytics template_values["system_version"] = VERSION path = os.path.join(os.path.dirname(__file__), "tpl", "writer", "settings.html") self.response.out.write(template.render(path, template_values))
def get(self): self.session = Session() if CheckAuth(self) is False: return DoAuth(self, "/writer/overview") 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"]) articles = memcache.get("writer_articles") if articles is None: articles = Article.all().order("-created") memcache.set("writer_articles", articles, 86400) paginator = ObjectPaginator(articles, PAGE_SIZE) try: page = int(self.request.get("page", 0)) articles = paginator.get_page(page) except InvalidPage: articles = paginator.get_page(int(paginator.pages - 1)) if paginator.pages > 1: is_paginated = True else: is_paginated = False if site_domain is None or site_name is None or site_author is None: site_configured = False else: site_configured = True if is_paginated: self.session["page"] = page urls = memcache.get("writer_urls") if urls is None: everything = Article.all().order("-title_url") urls = [] for article in everything: urls.append(article.title_url) memcache.set("writer_urls", urls, 86400) template_values = { "site_configured": site_configured, "is_paginated": is_paginated, "page_size": PAGE_SIZE, "page_has_next": paginator.has_next_page(page), "page_has_previous": paginator.has_previous_page(page), "page": page, "next": page + 1, "previous": page - 1, "pages": paginator.pages, "articles": articles, "articles_total": len(articles), "page_range": range(0, paginator.pages), "urls": urls, } if site_analytics is not None: template_values["site_analytics"] = site_analytics if site_domain_sync is None: q = site_domain else: q = site_domain + " OR " + site_domain_sync mentions_web = memcache.get("mentions_web") if mentions_web is None: try: mentions_web = feedparser.parse( "http://blogsearch.google.com/blogsearch_feeds?hl=en&q=" + urllib.quote("link:" + Datum.get("site_domain")) + "&ie=utf-8&num=10&output=atom" ) memcache.add("mentions_web", mentions_web, 600) except: mentions_web = None if mentions_web is not None: template_values["mentions_web"] = mentions_web.entries # mentions_twitter = memcache.get('mentions_twitter') # if mentions_twitter is None: # try: # result = urlfetch.fetch('http://search.twitter.com/search.json?q=' + urllib.quote(q)) # if result.status_code == 200: # mentions_twitter = simplejson.loads(result.content) # memcache.add('mentions_twitter', mentions_twitter, 600) # except: # mentions_twitter = None # if mentions_twitter is not None: # if len(mentions_twitter['results']) > 0: # template_values['mentions_twitter'] = mentions_twitter['results'] template_values["system_version"] = VERSION if "message" in self.session: template_values["message"] = self.session["message"] del self.session["message"] path = os.path.join(os.path.dirname(__file__), "tpl", "writer", "overview.html") self.response.out.write(template.render(path, template_values))
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)
def get(self, url): 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 pages = db.GqlQuery( "SELECT * FROM Article WHERE is_page = TRUE AND is_for_sidebar = TRUE ORDER BY title ASC" ) article = db.GqlQuery( "SELECT * FROM Article WHERE title_url = :1 LIMIT 1", url) if (article.count() == 1): article_found = True article = article[0] article.hits = article.hits + 1 try: article.put() except: article.hits = article.hits - 1 else: article_found = False if (article_found): if (article.article_set != None): if (len(article.article_set) > 0): try: q = db.GqlQuery( "SELECT * FROM Article WHERE article_set = :1 AND __key__ != :2 ORDER BY __key__ DESC LIMIT 10", article.article_set, article.key()) if q.count() > 0: template_values['related'] = q else: template_values['related'] = False except: template_values['related'] = False else: template_values['related'] = False else: template_values['related'] = False parent = None if article.parent is not '': q = db.GqlQuery( "SELECT * FROM Article WHERE title_url = :1 LIMIT 1", article.parent_url) if q.count() == 1: parent = q[0] template_values['parent'] = parent template_values['page_title'] = article.title template_values['article'] = article template_values['pages'] = pages template_values['pages_total'] = pages.count() 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, 'article.html') self.response.out.write(template.render(path, template_values)) else: template_values['page_title'] = 'Project Picky › Article Not Found' template_values['pages'] = pages template_values['pages_total'] = pages.count() 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, '404.html') self.response.out.write(template.render(path, template_values))
def post(self, key = ''): self.session = Session() if CheckAuth(self) is False: return DoAuth(self, '/writer') 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') site_default_format = Datum.get('site_default_format') if 'page' in self.session: page = self.session['page'] else: page = 0 site_default_format = Datum.get('site_default_format') if (self.request.get('content') != ''): if (key): article = db.get(db.Key(key)) article.title = self.request.get('title') article.title_link = self.request.get('title_link') article.title_url = self.request.get('title_url') article.parent_url = self.request.get('parent_url') article.content = self.request.get('content') article.format = self.request.get('format') if article.format not in CONTENT_FORMATS: article.format = site_default_format if article.format == 'markdown': article.content_formatted = markdown.markdown(article.content) if (self.request.get('is_page') == 'True'): article.is_page = True else: article.is_page = False if (self.request.get('is_for_sidebar') == 'True'): article.is_for_sidebar = True else: article.is_for_sidebar = False article.last_modified = datetime.datetime.utcnow() + datetime.timedelta(hours=+8) article.put() else: article = Article() article.title = self.request.get('title') article.title_link = self.request.get('title_link') article.title_url = self.request.get('title_url') article.parent_url = self.request.get('parent_url') article.content = self.request.get('content') article.format = self.request.get('format') if article.format not in CONTENT_FORMATS: article.format = site_default_format if article.format == 'markdown': article.content_formatted = markdown.markdown(article.content) if (self.request.get('is_page') == 'True'): article.is_page = True else: article.is_page = False if (self.request.get('is_for_sidebar') == 'True'): article.is_for_sidebar = True else: article.is_for_sidebar = False article.last_modified = datetime.datetime.utcnow() + datetime.timedelta(hours=+8) article.created = article.last_modified article.put() # Ping Twitter twitter_sync = Datum.get('twitter_sync') if twitter_sync == 'True' and article.is_page is False: twitter_account = Datum.get('twitter_account') twitter_password = Datum.get('twitter_password') if twitter_account != '' and twitter_password != '': api = twitter.Api(username=twitter_account, password=twitter_password) try: status = api.PostUpdate(article.title + ' http://' + site_domain_sync + '/' + article.title_url + ' (Sync via @projectpicky)') except: api = None obsolete = ['archive', 'archive_output', 'feed_output', 'index', 'index_output', 'writer_articles', 'writer_urls'] memcache.delete_multi(obsolete) Datum.set('site_updated', time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())) # Ping Google Blog Search 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')) + '/sitemap.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) except: taskqueue.add(url='/writer/ping') self.redirect('/writer/overview?page=' + str(page)) else: article = Article() article.title = self.request.get('title') article.title_link = self.request.get('title_link') article.title_url = self.request.get('title_url') article.content = self.request.get('content') article.format = self.request.get('format') if article.format not in CONTENT_FORMATS: article.format = site_default_format if (self.request.get('is_page') == 'True'): article.is_page = True else: article.is_page = False if (self.request.get('is_for_sidebar') == 'True'): article.is_for_sidebar = True else: article.is_for_sidebar = False template_values = { 'site_default_format' : site_default_format, 'article' : article, 'page_mode' : 'new', 'page_title' : 'New Article', 'page_reminder': reminder.writer_write, 'message' : message.content_empty, 'page' : page } if site_analytics is not None: template_values['site_analytics'] = site_analytics template_values['system_version'] = VERSION path = os.path.join(os.path.dirname(__file__), 'tpl', 'writer', 'write.html') self.response.out.write(template.render(path, template_values))
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') user = users.get_current_user() MODE_TWITTER = True class TwitterHomeHandler(webapp.RequestHandler): def get(self): self.session = Session() if CheckAuth(self) is False: return DoAuth(self, '/twitter')
def get(self, page=1): 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('index_output_a') if output is None: articles = memcache.get('index') if articles is None: articles = db.GqlQuery("SELECT * FROM Article WHERE is_page = FALSE ORDER BY created DESC LIMIT 12") memcache.add("index", articles, 86400) pages = db.GqlQuery("SELECT * FROM Article WHERE is_page = TRUE AND is_for_sidebar = TRUE ORDER BY title ASC") # Paginator by IIssNan ipage = ipaginator.Paginator(5, articles, page) template_values['is_paginated'] = ipage.is_paginator() template_values['page_list'] = ipage.list template_values['page_current'] = ipage.number template_values['has_previous'] = ipage.has_previous_page() template_values['has_next'] = ipage.has_next_page() template_values['articles'] = ipage.entries # end Paginator template_values['page_title'] = site_name template_values['articles_total'] = articles.count() template_values['pages'] = pages template_values['pages_total'] = pages.count() template_values['page_archive'] = False 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, 'index.html') output = template.render(path, template_values) memcache.set('index_output', output, 86400) self.response.out.write(output)
def get(self, url): 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 pages = db.GqlQuery("SELECT * FROM Article WHERE is_page = TRUE AND is_for_sidebar = TRUE ORDER BY title ASC") article = db.GqlQuery("SELECT * FROM Article WHERE title_url = :1 LIMIT 1", url) if (article.count() == 1): article_found = True article = article[0] article.hits = article.hits + 1 try: article.put() except: article.hits = article.hits - 1 else: article_found = False # 获取邻居文章 if (article_found): # 获取上一篇文章 try: q_prev = db.GqlQuery("SELECT * FROM Article WHERE __key__ < :1 AND is_page = false ORDER BY __key__ DESC LIMIT 1", article.key() ) if q_prev.count() > 0: template_values['entry_prev'] = q_prev[0] else: template_values['entry_prev'] = False except: template_values['entry_prev'] = False # 获取下一篇文章 try: q_next = db.GqlQuery("SELECT * FROM Article WHERE __key__ > :1 AND is_page = false ORDER BY __key__ DESC LIMIT 1", article.key() ) if q_next.count() > 0: template_values['entry_next'] = q_next[0] else: template_values['entry_next'] = False except: template_values['entry_next'] = False # 获取Article Set if (article_found): if (article.article_set != None): if (len(article.article_set) > 0): try: q = db.GqlQuery("SELECT * FROM Article WHERE article_set = :1 AND __key__ != :2 ORDER BY __key__ DESC LIMIT 10", article.article_set, article.key()) if q.count() > 0: template_values['related'] = q else: template_values['related'] = False except: template_values['related'] = False else: template_values['related'] = False else: template_values['related'] = False parent = None if article.parent is not '': q = db.GqlQuery("SELECT * FROM Article WHERE title_url = :1 LIMIT 1", article.parent_url) if q.count() == 1: parent = q[0] template_values['parent'] = parent template_values['page_title'] = article.title template_values['article'] = article template_values['pages'] = pages template_values['pages_total'] = pages.count() 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, 'article.html') self.response.out.write(template.render(path, template_values)) else: # 文章未找到 template_values['page_title'] = 'Caizpark › Article Not Found' template_values['pages'] = pages template_values['pages_total'] = pages.count() 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, '404.html') self.response.out.write(template.render(path, template_values))