This repository has been archived by the owner on Aug 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bergmanns.py
executable file
·150 lines (128 loc) · 4.38 KB
/
bergmanns.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
147
148
149
#!bin/python3
import sys
import configparser
import requests
from datetime import datetime, time, timedelta
from bs4 import BeautifulSoup
config = configparser.ConfigParser()
config.sections()
config.read('etc/bergmanns.ini')
username = config['User']['username']
password = config['User']['password']
domain = config['Website']['domain']
data = {'Login_Name': username, 'Login_Passwort': password}
### Tage ###
heute = datetime.combine(datetime.today(), time.min)
morgen = heute + timedelta(days=1)
uemorgen = heute + timedelta(days=2)
heute = int(heute.timestamp())
morgen = int(morgen.timestamp())
umorgen = int(uemorgen.timestamp())
sitemorgen = {'m': '2;1', 'sel_type': 'day', 'sel_date': morgen}
class color:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
#####
#####def main(domain, data):
##### cookie = get.login(domain, data).cookies
##### parse_morgen = get.get_day(domain, cookie, morgen)
##### get_namen(site_morgen)
#####
#####
#####if __name__ == "__main__":
##### main(domain, data)
#####
####### GET ###########
### VARIABLE ###
## Basics ##
#data = {'Login_Name': username, 'Login_Passwort': password}
#lin_param = {'ear_a': 'akt_login'}
#lout_param = {'ear_a': 'akt_login','a': 'login/logout'}
## Menu ##
## Übersicht #
#bestellung_alle = {'m': '2;1'}
#bestellung_tag = {'m': '2;1', 'sel_type': 'day', 'sel_date': date}
#bestellung_woche = {'m': '2;1', 'sel_type': 'week', 'sel_date': date}
## Speiseplan #
#wochenplan = {'m': '2;0'}
### Tage ###
heute = datetime.combine(datetime.today(), time.min)
morgen = heute + timedelta(days=1)
uemorgen = heute + timedelta(days=2)
heute_int = int(heute.timestamp())
morgen_int = int(morgen.timestamp())
umorgen_int = int(uemorgen.timestamp())
### Funktionen ###
#login to the website
def login(domain, data):
lin_param = {'ear_a': 'akt_login'}
login = requests.post(domain, data=data, params=lin_param)
return login
#logout from the website
def logout(cookie):
lout_param = {'ear_a': 'akt_login','a': 'login/logout'}
logout = requests.get(domain, params=lout_param, cookies=cookie)
return logout
#Menü aufrufen
def get_uri(domain, cookie, param):
response = requests.get(domain, cookies=cookie, params=param)
return response
#Bestellung an Datum abfragen
def get_day(domain, cookie, datum):
datum = {'m': '2;1', 'sel_type': 'day', 'sel_date': datum}
response = get_uri(domain, cookie, datum)
return response
###### Parse ######
#site = b.get_day(mb, b.umorgen).text
#bs = BeautifulSoup(site)
#
#bestellung = bs('table', attrs={'class':'auflistung bestellungen'})
#bestellung_head = bs('tr', attrs={'class':'head'})
#bestellung_artikel = bestellung.findAll('tr', attrs={'class':'auflistung0'})
#
#bestellung_nummer = bestellung.findAll('td',attrs={'class':'bestellungen_menuart'})
#bestellung_text = bestellung.findAll('td',attrs={'class':'bestellungen_menu'})
def get_nummern(site):
site = site.text
bs = BeautifulSoup(site, "lxml")
bestellung_nummer = bs.findAll('td',attrs={'class':'bestellungen_menuart'})
for i in bestellung_nummer:
nummern = print(''.join(i))
return nummern
def get_namen(site):
site = site.text
bs = BeautifulSoup(site, "lxml")
bestellung_text = bs.findAll('td',attrs={'class':'bestellungen_menu'})
text = []
for i in bestellung_text:
text.extend(i)
return text
if __name__ == "__main__":
print(color.HEADER,'Moment ich sehe kurz für dich nach',color.ENDC)
heute = datetime.combine(datetime.today(), time.min)
morgen = heute + timedelta(days=1)
login = login(domain, data)
if login.status_code != 200:
print(color.FAIL+'HTTP STATUSCODE == '+login.status_code+color.ENDC)
sys.exit()
cookie = login.cookies
liste = [heute, morgen]
for i in liste:
intday = int(i.timestamp())
parsed = get_day(domain, cookie, intday)
if parsed.status_code == 200:
print('Du hast am '+color.BOLD,i,color.ENDC+' folgendes bestellt')
essen = get_namen(parsed)
if not essen:
print(color.WARNING+'Du hast noch nicht bestellt'+color.ENDC)
else:
print(color.OKBLUE+'\n'.join(essen)+color.ENDC)
else:
print(color.FAIL+'Fehler beim Verbindungsaufbau'+color.ENDC)
logout(cookie)