Skip to content

Commit

Permalink
Featured art backend: Remote JSON in randomizer
Browse files Browse the repository at this point in the history
  • Loading branch information
romannurik committed Jun 28, 2020
1 parent 13f44fa commit e3db611
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion web/handlers/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
lt-artworks.json
lt-artworks.json
lt-artworks-url.txt
10 changes: 9 additions & 1 deletion web/handlers/randomizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import sys
import random

from google.appengine.api import urlfetch

from handlers import backroomarthelper
from handlers.common import *
from models import FeaturedArtwork
Expand All @@ -36,7 +38,13 @@ def artwork_key(details_url):

class PickRandomArtworkTaskHandler(BaseHandler):
def get(self):
ARTWORKS = json.loads(open(os.path.join(os.path.split(__file__)[0], 'lt-artworks.json')).read())
lt_artworks_url = open(os.path.join(os.path.split(__file__)[0], 'lt-artworks-url.txt')).read()
lt_result = urlfetch.fetch(lt_artworks_url)
if lt_result.status_code < 200 or lt_result.status_code >= 300:
raise IOError('Error downloading latest artworks JSON: HTTP %d.' % lt_result.status_code)
lt_artworks_json = lt_result.content

ARTWORKS = json.loads(lt_artworks_json)

# ARTWORKS = filter(lambda a: '_stars' in a and a['_stars'] >= 1, ARTWORKS)

Expand Down

0 comments on commit e3db611

Please sign in to comment.