Exemplo n.º 1
0
 def get(self):
   # add if does not exist entry else remove
   series = self.request.get('series')
   typ = self.request.get('typ')
   q = db.Query(UserData)
   q.filter("user ="******"http://SeriesWala.appspot.com/g?"  #FIX THIS URL FORMATION !!!
       paramsHD = {'s': series, 't': 'HD', 'e': added_series.latest_episode_HD}
       tmpsHD = urllib.urlencode(paramsHD)
       paramsSD = {'s': series, 't': 'SD', 'e': added_series.latest_episode_SD}
       tmpsSD = urllib.urlencode(paramsSD)
       linkHD = baseurl + tmpsHD
       linkSD = baseurl + tmpsSD
       if added_series.latest_episode_HD is not None:
         xmpp.send_message(users.get_current_user().email(), series + " HD " + added_series.latest_episode_HD + " " + linkHD)
       if added_series.latest_episode_SD is not None:
         xmpp.send_message(users.get_current_user().email(), series + " SD " + added_series.latest_episode_SD + " " + linkSD)
     db.put(ud)
     self.response.out.write('DONE')
   else:
     udo = UserData()
     udo.im_handle = users.get_current_user().nickname()
     udo.user = users.get_current_user().user_id()
     udo.series_subscribed = [series]
     db.put(udo)
     taskqueue.add(url='/invite', params={'email': users.get_current_user().email()})
     newq = db.Query(SeriesLatest)
     newq.filter('series_name = ', series)
     added_series = newq.get()
     # FIX: User may not have received invite yet
     if added_series.latest_episode_HD is not None:
       xmpp.send_message(users.get_current_user().email(), series + " HD " + added_series.latest_episode_HD)
     if added_series.latest_episode_SD is not None:
       xmpp.send_message(users.get_current_user().email(), series + " SD " + added_series.latest_episode_SD)
Exemplo n.º 2
0
  def get(self):
    standard = self.request.get('sd')
    # check if user signed-in or not
    user = users.get_current_user()
    logged = False
    udata = {}
    if user:
      logged = True
      udata['buttontext'] = user.nickname()
      udata['url'] = '#'
      if standard == 'true':
        udata['logout'] = users.create_logout_url("/?sd=true")
      else:
        udata['logout'] = users.create_logout_url("/")
    else:
      udata['buttontext'] = "Sign in with Google"
      if standard == 'true':
        udata['url'] = users.create_login_url("/?sd=true")
      else:
        udata['url'] = users.create_login_url("/")

    if standard == 'true':
      d = memcache.get('sdata')
      if d is None:
        try:
          d = process_and_return(hd=False)
          taskqueue.add(url='/updateseries?sd=true', method='GET')
        except:
          self.response.out.write('Oops seems like our source ThePirateBay is down.')
          return
        memcache.set('sdata', d)
      c = ['active', '', '']
    else:
      d = memcache.get('data')
      if d is None:
        try:
          d = process_and_return()
          taskqueue.add(url='/updateseries?sd=false', method='GET')
        except:
          self.response.out.write('Oops seems like our source ThePirateBay is down.')
          return
        memcache.set('data', d)
      c = ['', 'active', '']

    if d.has_key(''):
      d.pop('')
    subscribed = None
    if users.get_current_user() is not None:
      q = db.Query(UserData)
      q.filter("user =", users.get_current_user().user_id())
      ud = q.get()
      subscribed = []
      if ud is None:
        udo = UserData()
        udo.im_handle = users.get_current_user().nickname()
        udo.user = users.get_current_user().user_id()
        udo.series_subscribed = []
        db.put(udo)
        taskqueue.add(url='/invite', params={'email': users.get_current_user().email()})
      else:
        subscribed = ud.series_subscribed

    messages = []
    if users.get_current_user() is not None:
      q = db.Query(Messages)
      q.filter('user_email = ', users.get_current_user().email())
      msg_data = q.fetch(10)
      for m in msg_data:
        messages.append(m.message)

    template_values = {
            'messages': messages,
            'subscribed': subscribed,
            'logged': logged,
            'udata': udata,
            'data': OrderedDict(sorted(d.items())),
            'standard': c[0],
            'highdef': c[1],
            'about': c[2]
        }

    template = jinja_environment.get_template('index.html')
    self.response.out.write(template.render(template_values))