-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
executable file
·146 lines (121 loc) · 6.96 KB
/
app.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!flask/bin/python
import atexit
import requests
import datetime
import lxml.html
import os
from flask import Flask, jsonify
from datetime import date, timedelta
from apscheduler.scheduler import Scheduler
comicJSON = {}
app = Flask(__name__)
#Start CRON Job
cron = Scheduler()
cron.start()
@cron.interval_schedule(seconds = 180) #change it to 30 seconds on local system while testing
def job_function():
for comicName in ['garfield','dilbert','peanuts','hagar the horrible','dennis the menace','archie','pickles','beetle bailey','blondie','wizard of id','rugrats','zits','intelligent life','bizarro','marvin']:
if comicName == 'garfield':
comicHTML = lxml.html.document_fromstring(requests.get("http://garfield.com/").content)
img_src = comicHTML.xpath('//*[@id="home_comic"]/img/@src')[0]
#print "Case 1 Successful!"
comicJSON[comicName] = img_src
if comicName == "dilbert":
comicHTML = lxml.html.document_fromstring(requests.get("http://dilbert.com/").content)
img_src = comicHTML.xpath('/html/body/div[2]/div[3]/section/div[1]/a/img/@src')[0]
#print "Case 2 Successful!"
comicJSON[comicName] = img_src
#if comicName == "calvin and hobbes":
# comicHTML = lxml.html.document_fromstring(requests.get("http://www.gocomics.com/calvinandhobbes/").content)
# img_src = comicHTML.xpath('//*[@id="content"]/div[1]/p[1]/a/img/@src')[0]
# #print "Case 3 Successful!"
# comicJSON[comicName] = img_src
#if comicName == "bloom county":
# comicHTML = lxml.html.document_fromstring(requests.get("http://www.gocomics.com/bloomcounty/").content)
# img_src = comicHTML.xpath('//*[@id="content"]/div[1]/p[1]/a/img/@src')[0]
# print "Case 4 Successful!"
# comicJSON[comicName] = img_src
if comicName == "peanuts":
# print "Case 4 Successful!"
comicHTML = lxml.html.document_fromstring(requests.get("http://www.arcamax.com/thefunnies/peanuts/").content)
img_src = comicHTML.xpath('//*[@id="comic-zoom"]/@src')[0]
# print "Case 4 Successful!"
comicJSON[comicName] = "http://www.arcamax.com"+img_src
if comicName == "hagar the horrible":
comicHTML = lxml.html.document_fromstring(requests.get("http://www.arcamax.com/thefunnies/hagarthehorrible/").content)
img_src = comicHTML.xpath('//*[@id="comic-zoom"]/@src')[0]
# print "Case 4 Successful!"
comicJSON[comicName] = "http://www.arcamax.com"+img_src
if comicName == "dennis the menace":
comicHTML = lxml.html.document_fromstring(requests.get("http://www.arcamax.com/thefunnies/dennisthemenace/").content)
img_src = comicHTML.xpath('//*[@id="comic-zoom"]/@src')[0]
# print "Case 5 Successful!"
comicJSON[comicName] = "http://www.arcamax.com"+img_src
if comicName == "archie":
comicHTML = lxml.html.document_fromstring(requests.get("http://www.arcamax.com/thefunnies/archie/").content)
img_src = comicHTML.xpath('//*[@id="comic-zoom"]/@src')[0]
# print "Case 5 Successful!"
comicJSON[comicName] = "http://www.arcamax.com"+img_src
# print comicJSON[comicName]
if comicName == "pickles":
comicHTML = lxml.html.document_fromstring(requests.get("http://www.arcamax.com/thefunnies/pickles/").content)
img_src = comicHTML.xpath('//*[@id="comic-zoom"]/@src')[0]
# print "Case 6 Successful!"
comicJSON[comicName] = "http://www.arcamax.com"+img_src
# print comicJSON[comicName]
if comicName == "beetle bailey":
comicHTML = lxml.html.document_fromstring(requests.get("http://www.arcamax.com/thefunnies/beetlebailey/").content)
img_src = comicHTML.xpath('//*[@id="comic-zoom"]/@src')[0]
# print "Case 6 Successful!"
comicJSON[comicName] = "http://www.arcamax.com"+img_src
# print comicJSON[comicName]
if comicName == "blondie":
comicHTML = lxml.html.document_fromstring(requests.get("http://www.arcamax.com/thefunnies/blondie/").content)
img_src = comicHTML.xpath('//*[@id="comic-zoom"]/@src')[0]
# print "Case 6 Successful!"
comicJSON[comicName] = "http://www.arcamax.com"+img_src
# print comicJSON[comicName]
if comicName == "wizard of id":
comicHTML = lxml.html.document_fromstring(requests.get("http://www.arcamax.com/thefunnies/wizardofid/").content)
img_src = comicHTML.xpath('//*[@id="comic-zoom"]/@src')[0]
# print "Case 6 Successful!"
comicJSON[comicName] = "http://www.arcamax.com"+img_src
# print comicJSON[comicName]
if comicName == "rugrats":
comicHTML = lxml.html.document_fromstring(requests.get("http://www.arcamax.com/thefunnies/rugrats/").content)
img_src = comicHTML.xpath('//*[@id="comic-zoom"]/@src')[0]
# print "Case 6 Successful!"
comicJSON[comicName] = "http://www.arcamax.com"+img_src
# print comicJSON[comicName]
if comicName == "zits":
comicHTML = lxml.html.document_fromstring(requests.get("http://www.arcamax.com/thefunnies/zits/").content)
img_src = comicHTML.xpath('//*[@id="comic-zoom"]/@src')[0]
# print "Case 6 Successful!"
comicJSON[comicName] = "http://www.arcamax.com"+img_src
# print comicJSON[comicName]
if comicName == "intelligent life":
comicHTML = lxml.html.document_fromstring(requests.get("http://www.arcamax.com/thefunnies/intelligentlife/").content)
img_src = comicHTML.xpath('//*[@id="comic-zoom"]/@src')[0]
# print "Case 6 Successful!"
comicJSON[comicName] = "http://www.arcamax.com"+img_src
# print comicJSON[comicName]
if comicName == "bizarro":
comicHTML = lxml.html.document_fromstring(requests.get("http://www.arcamax.com/thefunnies/bizarro/").content)
img_src = comicHTML.xpath('//*[@id="comic-zoom"]/@src')[0]
# print "Case 6 Successful!"
comicJSON[comicName] = "http://www.arcamax.com"+img_src
# print comicJSON[comicName]
if comicName == "marvin":
comicHTML = lxml.html.document_fromstring(requests.get("http://www.arcamax.com/thefunnies/marvin/").content)
img_src = comicHTML.xpath('//*[@id="comic-zoom"]/@src')[0]
# print "Case 6 Successful!"
comicJSON[comicName] = "http://www.arcamax.com"+img_src
# print comicJSON[comicName]
atexit.register(lambda: cron.shutdown(wait=False))
@app.route('/getComicLinks', methods=['GET'])
def get_tasks():
#print "Request Handled"
return jsonify(comicJSON)
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port,debug=True)