/
fetch.py
35 lines (26 loc) · 987 Bytes
/
fetch.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
from google.appengine.api import mail
from google.appengine.api import memcache
from google.appengine.ext import webapp, db
from google.appengine.ext.webapp import util, template
from google.appengine.ext.webapp.util import run_wsgi_app
from django.utils import simplejson
import utils
from models import User, Post, Comment, Notification, Ticket
class FetchHandler(webapp.RequestHandler):
def get(self):
tic = utils.microtime(True)
for n in range(1, 11):
json_url = 'http://www.noticiashacker.com/nuevo.json?pagina=%d'
noticias = utils.getJson(json_url % n)
for noticia in noticias['posts']:
user = utils.put_user(noticia['user'])
post = utils.put_post(noticia,user)
toc = utils.microtime(True)
print "Time elapsed %f seconds" % (toc-tic)
def main():
application = webapp.WSGIApplication([
('/tasks/fetch', FetchHandler)
], debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()