This repository was archived by the owner on Jun 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheuteinma.py
More file actions
140 lines (122 loc) · 5.98 KB
/
Copy pathheuteinma.py
File metadata and controls
140 lines (122 loc) · 5.98 KB
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
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), "lib"))
import facebook
import websites
import feeds
#import beachstatus
from event import EventVault
import logging
import datetime
import time
import locale
locale.setlocale(locale.LC_TIME, '') # locale for date, time an the infamous german "Umalaute"
LOG_FILENAME = os.path.join(os.path.dirname(__file__), 'log.log')
logging.basicConfig(filename=LOG_FILENAME, level=logging.ERROR)
class HeuteInMannheim:
def __init__(self):
super(HeuteInMannheim, self).__init__()
self.vault = EventVault() # Initialize main Storage Object
# Initialize Scrapers
self.facebook_scraper = facebook.FacebookScraper(self.vault)
self.website_scraper = websites.WebsiteScraper(self.vault)
self.feed_scraper = feeds.FeedScraper(self.vault)
self.events = self.vault.get_events_for_date(datetime.date.today())
#self.events = self.vault.get_all_events() # Only for testing/debugging
#self.beach_status = beachstatus.BeachStatus()
#self.beach_status = self.beach_status.get_status()
self.state_output = self.make_html()
self.write_html() # Make initial index.html
logging.info("Total amount of Events: " + str(len(self.vault.get_all_events())))
def make_html(self):
"""Generate HTML output from collected events"""
output = """<!DOCTYPE html>
<html>
<head>
<title>Heute in Mannheim</title>
<link href="style.css" media="all" rel="stylesheet" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="description" content="Heute in Mannheim ist eine simple Website, die dir Events in Mannheim anzeigt. Unabhängig, werbefrei, unkommerziell, free as in freedom and free as in beer.">
<meta name="apple-mobile-web-app-capable" content="yes">
</head>
<body>
<table>\n"""
if not self.events: # Guess we're staying home tonight...
output += """<tr><td><p><span class=\"title\">Heute keine
Events.<br> Guess we're staying home tonight...
:-(</span></p></td></tr>\n"""
else:
eo = 0 # Even/Odd table-rows
for event in self.events:
if eo == 0:
output += " <tr class=\"even\">"
eo = 1
else:
output += " <tr class=\"odd\">"
eo = 0
# Facebook Icon by http://shimmi1.deviantart.com/ to warn Users from evil Facebook links
if event.get("event_url").find("facebook") > -1:
output_fb = "<img src=\"img/fb_ico.png\" alt=\"Achtung: Facebook Link!\">"
else:
output_fb = ""
output += """
<td><p><span class=\"title\"><a href=\"{}\">{} {}</a></span></p>
<span class=\"location\"><a href=\"{}\">{}</a></span><br>
<span class=\"adresse\">{} {} | {} {}</span></td>
<td><span class=\"zeit\">{}</span><br>
</tr>\n""".format(event.get("event_url"),
event.get("title"),
output_fb,
event.get("url"),
event.get("name"),
event.get("strasse"),
event.get("hausnr"),
event.get("plz"),
event.get("ort"),
event.get("uhrzeit"))
# output += """
# </table>
# <hr>
# <p><b>Status der Mannheimer Strände:</b></p>
# <table>"""
# for beach in self.beach_status:
# hours = ""
# if beach["status"] == "open":
# hours = str("<b>" + beach["hours_open"] + " - " + beach["hours_closed"] + "</b><br>")
# output += """
# <tr class=\"beach\">
# <td class=\"{}\">
# <span class=\"adresse"><a href=\"{}\">{}: {}</a></span><br>
# {}
# {} {} | {} {}
# </td>
# </tr>""".format(beach["status"],
# beach["event_obj"].get("url"),
# beach["event_obj"].get("name"),
# beach["status"],
# hours,
# beach["event_obj"].get("strasse"),
# beach["event_obj"].get("hausnr"),
# beach["event_obj"].get("plz"),
# beach["event_obj"].get("ort"))
output += """
</table>
<hr>
<p>Last update: {}</p>
<p><b><a href=\"imprint.html\">Contact, Impressum und Datenschutz</a></b></p>
<p class=\"footer\">Heute in Mannheim ist eine automatisch generierte
Website und wurde nach bestem Wissen und Gewissen erstellt. Die
Einträge wurden nicht redaktionell bearbeitet und ich übernehme
keinerlei Haftung für die Inhalte hinter den links</p>
<p class=\"footer\"><a href=\"https://github.com/s1lvester/heuteinmannheim\">Fork me on GitHub</a><br>Danke an die Jungs von <a href=\"http://heuteinstuttgart.de/\">heuteinstuttgart.de</a></p>
</body>
</html>""".format(time.strftime("%d.%m.%Y %H:%M", time.localtime()))
return output.encode("utf-8")
def write_html(self):
"""Write the index.html file. Requires self.state_output to be set"""
f = open(os.path.join(os.path.dirname(__file__), "static/index.html"),
"wb")
f.write(self.state_output)
f.close()
# Gooo !!!!11einself
main_obj = HeuteInMannheim()