Ablauf verbessert
This commit is contained in:
		
							parent
							
								
									69b0311f9f
								
							
						
					
					
						commit
						13716aa464
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					*.csv
 | 
				
			||||||
@ -69,6 +69,19 @@ def init(key, modus, host, headers):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return name, value
 | 
					    return name, value
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def read_file(jahr):
 | 
				
			||||||
 | 
						''' Liest Daten aus muell<jahr>.csv und liefert ggf. Ergebnis zurück'''
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						antwort_liste = None
 | 
				
			||||||
 | 
						try:
 | 
				
			||||||
 | 
							f = open(f'muell{jahr}.csv', 'rb')
 | 
				
			||||||
 | 
							antwort = str(f.read())
 | 
				
			||||||
 | 
							antwort_liste = antwort[antwort.find('Biom'):].strip("'").replace('\\n', '\n').split('\n')
 | 
				
			||||||
 | 
						except FileNotFoundError:
 | 
				
			||||||
 | 
							pass
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
						return antwort_liste
 | 
				
			||||||
 | 
						
 | 
				
			||||||
# Variablen
 | 
					# Variablen
 | 
				
			||||||
key = 'e21758b9c711463552fb9c70ac7d4273'
 | 
					key = 'e21758b9c711463552fb9c70ac7d4273'
 | 
				
			||||||
modus = 'd6c5855a62cf32a4dadbc2831f0f295f'
 | 
					modus = 'd6c5855a62cf32a4dadbc2831f0f295f'
 | 
				
			||||||
@ -106,35 +119,31 @@ muell_arten = [
 | 
				
			|||||||
    'Schadstoffmobil',
 | 
					    'Schadstoffmobil',
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# __main__
 | 
					# __main__
 | 
				
			||||||
config = readConfig()
 | 
					antwort_liste = read_file(current_year)
 | 
				
			||||||
postdata['f_id_kommune'] = config['kommune']
 | 
					if antwort_liste == None:
 | 
				
			||||||
postdata['f_id_strasse'] = config['strasse']
 | 
					    # Keine vernünftigen Daten, ergo mal gucken, was die Webseite ergibt
 | 
				
			||||||
 | 
						config = readConfig()
 | 
				
			||||||
 | 
						postdata['f_id_kommune'] = config['kommune']
 | 
				
			||||||
 | 
						postdata['f_id_strasse'] = config['strasse']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(name, value) = init(key, modus, host, headers)
 | 
						(name, value) = init(key, modus, host, headers)
 | 
				
			||||||
if name != None and value != None:
 | 
						if name != None and value != None:
 | 
				
			||||||
		postdata[name] = value
 | 
							postdata[name] = value
 | 
				
			||||||
 | 
					
 | 
				
			||||||
http = httplib2.Http()
 | 
						http = httplib2.Http()
 | 
				
			||||||
(resp, content) = http.request(url, "POST", headers = headers, body = urllib.parse.urlencode(postdata))
 | 
						(resp, content) = http.request(url, "POST", headers = headers, body = urllib.parse.urlencode(postdata))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
antwort = str(content)
 | 
						antwort = str(content)
 | 
				
			||||||
antwort_liste = antwort[antwort.find('Biom'):].strip("'").replace('\\n', '\n').split('\n')
 | 
						f = open(f'muell{current_year}.csv', 'wb')
 | 
				
			||||||
 | 
						f.write(content)
 | 
				
			||||||
if antwort_liste[0] == '':
 | 
						f.close()
 | 
				
			||||||
    # Keine vernünftigen Daten, ergo mal gucken, was in der Datei steht
 | 
					 | 
				
			||||||
    try:
 | 
					 | 
				
			||||||
        f = open('muell.csv', 'rb')
 | 
					 | 
				
			||||||
        antwort = str(f.read())
 | 
					 | 
				
			||||||
	antwort_liste = antwort[antwort.find('Biom'):].strip("'").replace('\\n', '\n').split('\n')
 | 
						antwort_liste = antwort[antwort.find('Biom'):].strip("'").replace('\\n', '\n').split('\n')
 | 
				
			||||||
    except FileNotFoundError:
 | 
					 | 
				
			||||||
        pass
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
daten = set(antwort_liste)
 | 
					daten = set(antwort_liste)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for datum in daten:
 | 
					for datum in daten:
 | 
				
			||||||
 | 
					    tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y')
 | 
				
			||||||
    datum = datum.split(';')
 | 
					    datum = datum.split(';')
 | 
				
			||||||
    l_muell = get_index_positions(datum, tomorrow)
 | 
					    l_muell = get_index_positions(datum, tomorrow)
 | 
				
			||||||
    if len(l_muell) > 0:
 | 
					    if len(l_muell) > 0:
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user