-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
50 lines (37 loc) · 1.12 KB
/
worker.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
##############################
# COVID-19 risk area monitor #
##############################
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'web.settings'
import django
from django.conf import settings
django.setup()
import re
import requests
from cram.models import Page, Subscription
DE_PAGE = Page.objects.get(id=1)
URL = DE_PAGE.url
XPATH_COUNTRY = DE_PAGE.xpath_country
REGEX_COUNTRY = DE_PAGE.regex_country
REGEX_TIME = DE_PAGE.regex_time
MY_SUBSCRIPTION = Subscription.objects.get(id=1)
COUNTRY = MY_SUBSCRIPTION.country
def get_xpath(country):
return XPATH_COUNTRY.format(country)
def get_regex_country(country):
return REGEX_COUNTRY.format(country)
def get_emails():
return os.environ.get('EMAILS')
def fetch_url(url):
response = requests.get(url)
return response.text
def get_time(html):
return re.search(REGEX_TIME, html).group()
def get_country_areas(html, country):
return re.search(get_regex_country(country), html).group()
def main():
html = fetch_url(URL)
print('Time: {}'.format(get_time(html)))
print(get_country_areas(html, COUNTRY))
if __name__ == '__main__':
main()