Пример #1
0
 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))
Пример #2
0
 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')
Пример #3
0
 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)
Пример #4
0
 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))
Пример #5
0
    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)
Пример #6
0
 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))