-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
98 lines (78 loc) · 3.71 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# This script updates the database on getting a GET request by CRON jobs.
import webapp2, logging, imdb
from google.appengine.ext import db
from google.appengine.api import memcache
from NextEp import getNextEp
from Databases import Series, ListSeries, Total
class UpdateSeries(webapp2.RequestHandler):
'''
On receiving a GET request (From a cron job mainly) these steps are undertaken
1. Extractor iterator value from Memcache and the maximum value
2. Corresponding to the iterator value, extract the movie ID from ListSeries class
3. Extract all the information of the series and update the database
'''
def get(self):
logging.info("Received a GET Request")
iterator = memcache.get('iterator') #Get value of iterator in memcache
total = memcache.get('total') #Get value of total in memcache
if iterator is None: # In case there is no iterator, make an iterator and initialise with value 0
iterator = 0
memcache.add('iterator',iterator)
if total is None: # In case there is no total in the memcache, get total from datastore and add to memcache
db_total = Total.all().get()
total = db_total.total
memcache.add('total', total)
iterator = iterator + 1 #Incrementing the iterator and reset if equal to max
if(iterator >= total+1):
iterator = 1
memcache.set('iterator', iterator)
logging.info("New Iterator Value " + str(iterator))
# Now get the corresponding id from ListSeries
lsquery = ListSeries.all()
lsquery.filter("slno =", iterator)
serial = lsquery.get()
stvid = serial.tvid
logging.info("IMDb ID " + stvid)
self.response.write(stvid)
episode = getNextEp(stvid)
epNum = episode["episode"]
seaNum = episode["season"]
epName = episode["title"]
epStat = episode["status"]
epRely = episode["rely"]
epComments = episode['comments']
if epRely == 3: # No air date present
epDate = 'Unavailable'
else:
epDate = episode["original air date"]
if epStat != 99:
logging.info("Episode Number " + str(epNum))
logging.info("Season Number " + str(seaNum))
logging.info("Episode Title " + epName)
logging.info("Status " + str(epStat))
logging.info("Reliable " + str(epRely))
logging.info("Next Episode date " + epDate)
logging.info("Comments " + epComments)
else:
logging.warn("There is no information about the next episode. Probably the series has been terminated.")
logging.info("Last Known Episode Number " + str(epNum))
logging.info("Last Known Season Number " + str(seaNum))
logging.info("Last Known Episode Title " + epName)
logging.info("Status " + str(epStat))
logging.info("Reliable " + str(epRely))
logging.info("Last Known Episode date " + epDate)
logging.info("Comments " + epComments)
Ser = Series.all()
Ser.filter('tvid = ', str(stvid))
ser1 = Ser.get()
logging.info("entry extracted from datastore")
ser1.status = epStat
ser1.rely = epRely
ser1.epname = epName
ser1.epinfo = str(seaNum) + "." + str(epNum)
ser1.epdate = epDate
ser1.up_cycle = ser1.up_cycle + 1
ser1.comments = epComments
ser1.put()
logging.info(" Updated data written to Datastore")
application= webapp2.WSGIApplication([("/update",UpdateSeries),],debug=True)