Example #1
0
  def get(self):

    #
    # Setup the template values, may as well throw the guardian api
    # key in there at the same time
    #
    template_values = {
      'guardian_api_key': passwords.guardian_api_key(),
    }
    
    #
    # Now I want to know what articles are waiting to be reviewed and so on
    #
    rows = db.GqlQuery("SELECT * FROM Items WHERE unreviewed = 1")
    
    #
    # Yes, yes I know this is dumb, so go make it better, anyway I just want this
    # crap to work, so I'm going to loop over the json, load it, shove it into
    # an array and then just dump the whole thing out again, with some
    # gnarly replacing, just to make it look nice ... I know, I know, blame
    # the older version of Django being used by App Engine, when they
    # update to something sensible *then* I'll clean this up, ok?!
    #
    json_a = []
    for row in rows:
      new_json = simplejson.loads(row.json)
      new_json['response']['content']['fields']['time_spent'] = (row.time_spent)
      new_json['response']['content']['fields']['view_count'] = (row.view_count)
      new_json['response']['content']['fields']['percent'] = (row.percent)
      json_a.append(new_json)
      
    template_values['review_items'] = simplejson.dumps(json_a).replace('\/','/').replace('}}}, {', '}}},\n{') # << larks!!!
    
    #
    # Now I want to know what articles are waiting to be reviewed and so on
    #
    rows = db.GqlQuery("SELECT * FROM Items WHERE queued = 1 ORDER BY last_update ASC")
    
    json_a = []
    for row in rows:
      new_json = simplejson.loads(row.json)
      new_json['response']['content']['fields']['time_spent'] = (row.time_spent)
      new_json['response']['content']['fields']['view_count'] = (row.view_count)
      new_json['response']['content']['fields']['percent'] = (row.percent)
      json_a.append(new_json)
      
    template_values['queued_items'] = simplejson.dumps(json_a).replace('\/','/').replace('}}}, {', '}}},\n{') # << larks!!!
    

    path = os.path.join(os.path.dirname(__file__), 'templates/index.html')
    self.response.out.write(template.render(path, template_values))
except Exception:
  print ''
  print 'application is missing the passwords file'
  sys.exit()






#
# Setup the template values, may as well throw the guardian api
# key in there at the same time
#
template_values = {
  'guardian_api_key': passwords.guardian_api_key(),
}

#
# Now I want to know what articles are waiting to be reviewed and so on
#

rows = db.GqlQuery("SELECT * FROM Items ORDER BY last_update DESC LIMIT 200")

counter = 1
keys = []
for row in rows:
  
  try:
    if row.word_count >= 1000:
      json = simplejson.loads(row.json)
  def get(self):

    #
    # Setup the template values, may as well throw the guardian api
    # key in there at the same time
    #
    template_values = {
      'guardian_api_key': passwords.guardian_api_key(),
    }
    
    #
    # Now I want to know what articles are waiting to be reviewed and so on
    #
    rows = db.GqlQuery("SELECT * FROM Items WHERE published = 1 AND queued = 0 ORDER BY published_ordinal DESC LIMIT 14")
    
    #
    # Yes, yes I know this is dumb, so go make it better, anyway I just want this
    # crap to work, so I'm going to loop over the json, load it, shove it into
    # an array and then just dump the whole thing out again, with some
    # gnarly replacing, just to make it look nice ... I know, I know, blame
    # the older version of Django being used by App Engine, when they
    # update to something sensible *then* I'll clean this up, ok?!
    #
    json_a = []
    for row in rows:
      
      new_json = simplejson.loads(row.json)
      new_json['response']['content']['fields']['time_spent'] = (row.time_spent)
      new_json['response']['content']['fields']['view_count'] = (row.view_count)
      new_json['response']['content']['fields']['percent'] = (row.percent)
      d = date.fromordinal(row.published_ordinal)
      dow = d.strftime("%A")
      new_json['response']['content']['fields']['published_ordinal'] = (row.published_ordinal)
      new_json['response']['content']['fields']['dow'] = dow
      
      # Now I want to go thru all the tags finding out where we first published it
      publishedIn = 'The Guardian'
      for tag in new_json['response']['content']['tags']:
        if tag['type'] == 'publication':
          publishedIn = tag['webTitle']
      new_json['response']['content']['fields']['publishedIn'] = publishedIn.replace('The', 'the')
      
      # And get the publication date
      d = datetime.strptime(new_json['response']['content']['webPublicationDate'].replace('T',' ').replace('Z', '').split(' ')[0], '%Y-%m-%d')
      new_json['response']['content']['fields']['publishedOn'] = datetime.strftime(d, '%a %d %b %Y')
      new_json['response']['content']['fields']['publishedFull'] = 'First published in ' + new_json['response']['content']['fields']['publishedIn'] + ' on ' + new_json['response']['content']['fields']['publishedOn']
      new_json['response']['content']['fields']['publishedFull'] = 'First published in ' + new_json['response']['content']['sectionName'] + ' on ' + new_json['response']['content']['fields']['publishedOn']
      
      
      tagsList = []
      for tag in new_json['response']['content']['tags']:
        if tag['type'] == 'keyword':
          tagsList.append(tag['webTitle'])
      new_json['response']['content']['fields']['tagsList'] = tagsList
      

      json_a.append(new_json)
          
    json_a.reverse()
      
    template_values['published_items'] = simplejson.dumps(json_a).replace('\/','/').replace('}}}, {', '}}},\n{') # << larks!!!
    template_values['json'] = json_a
    
    

    path = os.path.join(os.path.dirname(__file__), 'templates/kindle.html')
    self.response.out.write(template.render(path, template_values))