Beispiel #1
0
 def get(self):
     rdic = {}
     source = self.request.get('from', None)
     message = ''
     if source:
         session = Session(self)
         message = session.get('message','')
         session.delete('message')
     rdic['message'] = message
     comments = memcache.get('disqus$comments')
     ua = self.request.headers.get('User-Agent', 'bot')
     path = get_path(ua, 'dashboard.html')
     rdic['notes'] = dbs.Note.getten()
     if comments is not None:
         rdic['comments'] = comments
         return self.response.out.write(render(path,rdic))
     disqus_key = dbs.Vigo.get('disqus_key')
     disqus_forumid = dbs.Vigo.get('disqus_forumid')
     mydisqus = Disqus(disqus_key)
     mydisqus.get_forum_posts_rpc(disqus_forumid)
     result = mydisqus.get_forum_posts_result()
     comments = mydisqus.parse_data(result)
     memcache.set('god$comments', comments, 10800) # 3 hours
     rdic['comments'] = comments
     return self.response.out.write(render(path,rdic))
Beispiel #2
0
 def get(self):
     ua = self.request.headers.get('User-Agent', 'bot')
     path = get_path(ua, 'douban_dashboard.html')
     rdic = {}
     source = self.request.get('from', None)
     message = ''
     if source:
         session = Session(self)
         message = session.get('message','')
         session.delete('message')
     rdic['message'] = message
     qs = dbs.Vigo.get('oauth_douban')
     if not qs:
         return self.redirect('/god/douban/login')
     api = pydouban.Api()
     api.set_qs_oauth(config.douban_key, config.douban_secret, qs)
     profile = memcache.get('douban/profile')
     if profile is None:
         profile = api.get_profile()
         memcache.set('douban/profile', profile, day)
     rdic['profile'] = profile
     miniblogs = memcache.get('douban/miniblogs')
     if miniblogs is None:
         miniblogs = api.get_contacts_miniblog()
         for i in range(len(miniblogs.entry)):
             miniblogs.entry[i].published.t = datetime.datetime.strptime(
                 miniblogs.entry[i].published.t, '%Y-%m-%dT%H:%M:%S+08:00')
             miniblogs.entry[i].published.t -= datetime.timedelta(hours=8)
         memcache.set('douban/miniblogs', miniblogs, 240)
     rdic['miniblogs'] = miniblogs
     return self.response.out.write(render(path, rdic))
Beispiel #3
0
class LoginHandler(webapp.RequestHandler):
    def get(self):
        doRender(self,'login.html')

    def post(self):
        self.session = Session()
        id_ = self.request.get('username')        
        pw = self.request.get('password')
        self.session.delete_item('username')

        if id_ == '':
            doRender(self, 'login.html', {'error':'Please specify a username.'})
            return
        if pw == '':
            doRender(self, 'login.html', {'error':'Please specify a password.'})
            return
        
        user = Student.get_by_username(id_)
        if user is None:
            doRender(self,'login.html',{'error':'Invalid username entered. Please try again.  '})  
        elif pw == user.password:
            self.session['username'] = id_
            self.session['student_id'] = user.key().id()
            if user.isAdmin:
                self.session['admin'] = True
            self.redirect('/profile')
        else:
            doRender(self,'login.html',{'error':'Invalid password entered. Please try again.'})
Beispiel #4
0
 def get(self):
     session = Session(self)
     oauth_douban = dbs.Vigo.get('oauth_douban')
     if oauth_douban:
         session['message'] = 'Douban Authed Already'
         return self.redirect('/god/douban?from=douban')
     auth = pydouban.Auth(config.douban_key, config.douban_secret)
     dic = session.get('douban_dic',{})
     if not dic:
         session['message'] = 'Request Douban access token failed'
         return self.redirect('/god?from=douban')
     qs = auth.get_acs_token(dic['oauth_token'],dic['oauth_token_secret'])
     dbs.Vigo.set('oauth_douban', qs)
     session['message'] = 'Douban Auth Success'
     return self.redirect('/god/douban?from=douban')
Beispiel #5
0
 def get(self):
     qs = dbs.Vigo.get('oauth_twitter')
     if qs:
         return self.response.out.write('authed')
     session = Session(self)
     qs = session.get('twitter_qs','')
     if not qs:
         session['message'] = 'Request Twitter access token failed'
         return self.redirect('/god?from=twitter')
     auth = Twitter()
     auth.set_qs_token(qs)
     url = auth.get_url(twitter.ACCESS_TOKEN_URL)
     dbs.Vigo.set('oauth_twitter', qs)
     session['message'] = 'Twitter Auth Success'
     return self.redirect('/god/twitter?from=auth')
Beispiel #6
0
 def get(self):
     source = self.request.get('from', None)
     message = ''
     if source:
         session = Session(self)
         message = session.get('message','')
         session.delete('message')
     status = self.request.get('filter', 'none')
     rdic = {}
     rdic['message'] = message
     data = self.get_filter(status)
     p = self.request.get('p',1)
     rdic['mvdata'] = Paginator(data, count, p)
     ua = self.request.headers.get('User-Agent', 'bot')
     path = get_path(ua, 'melody.html')
     return self.response.out.write(render(path,rdic))
Beispiel #7
0
class SignupHandler(webapp.RequestHandler):
    def get(self) :
        self.session = Session()
        self.session.delete_item('username')
        s = Student()
        s.generateID()
        s.generatePassword() 
        s.put()
        user = s
        user.put()
        self.session['username'] = user.id_
        self.session['student_id'] = s.key().id()
        doRender(self, 'issueAccount.html', {'student' : s})

    # old version - let user enter their username (email) and password
    """
Beispiel #8
0
 def get(self) :
     self.session = Session()
     self.session.delete_item('username')
     s = Student()
     s.generateID()
     s.generatePassword() 
     s.put()
     user = s
     user.put()
     self.session['username'] = user.id_
     self.session['student_id'] = s.key().id()
     doRender(self, 'issueAccount.html', {'student' : s})
Beispiel #9
0
class LogoutHandler(webapp.RequestHandler):
    def get(self):
        self.session = Session()
        self.session.delete_item('username')
        self.session.delete_item('student_id')
        self.session.delete_item('admin')
        doRender(self,'index.html')
Beispiel #10
0
 def get(self):
     source = self.request.get('from', None)
     message = ''
     if source:
         session = Session(self)
         message = session.get('message','')
         session.delete('message')
     rdic = {}
     action = self.request.get('action', 'none').lower()
     key = self.request.get('key', 'none')
     status = self.request.get('draft', '2')
     if 'draft' == action or 'post' == action:
         art = db.get(key)
         if art and 'draft' == action:
             art.draft = True
             art.put()
             memcache.delete('a/' + art.slug)
             memcache.delete('a$ten')
         elif art and 'post' == action:
             art.draft = False
             art.put()
             memcache.delete('a/' + art.slug)
             memcache.delete('a$ten')
         else:
             session = Session(self)
             session['message'] = "Can't find the article"
         return self.redirect('/god/article?from='+action)
     if 'filter' == action:
         data = self.get_filter(status)
     elif 'find' == action:
         data = self.get_find(key)
     else:
         data = dbs.Article.gql('ORDER BY created DESC')
     rdic['message'] = message
     p = self.request.get('p',1)
     rdic['mvdata'] = Paginator(data, count, p)
     ua = self.request.headers.get('User-Agent', 'bot')
     path = get_path(ua, 'article.html')
     return self.response.out.write(render(path,rdic))
Beispiel #11
0
 def get(self):
     ua = self.request.headers.get('User-Agent', 'bot')
     path = get_path(ua, 'twitter_dashboard.html')
     rdic = {}
     source = self.request.get('from', None)
     message = ''
     if source:
         session = Session(self)
         message = session.get('message','')
         session.delete('message')
     rdic['message'] = message
     qs = dbs.Vigo.get('oauth_twitter')
     if not qs:
         return self.redirect('/god/twitter/login')
     api = Twitter().set_qs_api(qs)
     statuses = memcache.get('twitter$home')
     if statuses is None:
         statuses = api.GetFriendsTimeline(count=30, retweets=True)
         for i in range(len(statuses)):
             statuses[i].datetime = datetime.datetime.\
                     fromtimestamp(time.mktime(time.strptime(statuses[i].created_at, '%a %b %d %H:%M:%S +0000 %Y')))
         memcache.set('twitter$home', statuses, 120)
     rdic['statuses'] = statuses
     return self.response.out.write(render(path, rdic))
Beispiel #12
0
from textwrap import shorten
from utils.common import InspectorAbstract
from utils.sessions import Session

session = Session("https://google.com", "https://www.youtube.com")


class GoogleCheck(InspectorAbstract):
    interval = 10
    name = 'Google Main Page'

    def check(self):
        response = session.head("https://google.com")
        self.details = {'status': response.status_code, 'headers': response.headers}
        return response.ok


class YoutubeCheck(InspectorAbstract):
    interval = 60
    name = 'Youtube Main Page'

    def check(self):
        response = session.get("https://www.youtube.com")
        self.details = {'status': response.status_code,
                        'content': shorten(response.content.decode(), width=128)}
        return response.ok
Beispiel #13
0
from utils.common import InspectorAbstract
from utils.sessions import Session

TEST_URL = 'https://example.con'
session = Session(TEST_URL)


class TestClass(InspectorAbstract):
    name = 'testClass'
    interval = 100

    def check(self):
        response = session.get(TEST_URL)
        self.set_details_from_response(response)
        return response.ok


class TestClass2(TestClass):
    name = 'TestClass2'
Beispiel #14
0
 def get(self):
     self.session = Session()
     self.session.delete_item('username')
     self.session.delete_item('student_id')
     self.session.delete_item('admin')
     doRender(self,'index.html')