Compare commits
No commits in common. "master" and "develop" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1 @@
|
|||||||
*.csv
|
*.csv
|
||||||
__pycache__
|
|
||||||
|
@ -10,15 +10,11 @@ Um die Daten an Telegram zu senden, musst du dir ein Skript/Programm schreiben,
|
|||||||
von Telegram verwendet und Daten an dich oder deine Gruppe senden kann!
|
von Telegram verwendet und Daten an dich oder deine Gruppe senden kann!
|
||||||
|
|
||||||
Beispiel für eine Konfigurationsdatei:
|
Beispiel für eine Konfigurationsdatei:
|
||||||
|
tgReceiver: <hier die ID der Gruppe/ des Teilnehmers eintragen>
|
||||||
kommune: 2601
|
kommune: 2601
|
||||||
strasse: 2146
|
strasse: 2146
|
||||||
telegram:
|
pathBot: '~/bin/YMBot'
|
||||||
tgReceiver: <hier die ID der Gruppe/ des Teilnehmers eintragen>
|
tgBotOwner: <hier DEINE Telegram-ID eintragen>
|
||||||
pathBot: '~/bin/YMBot'
|
|
||||||
signal:
|
|
||||||
path: "~/bin/signal-cli"
|
|
||||||
account: "+49<deine Mobilfunknummer>"
|
|
||||||
group_id: "<siehe 'signal-cli listGroups'>"
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
@ -49,7 +45,7 @@ def readConfig():
|
|||||||
home = Path.home() # home ist ohne / am Ende!
|
home = Path.home() # home ist ohne / am Ende!
|
||||||
config = {}
|
config = {}
|
||||||
with open(f'{home}/.muell.yaml', 'r') as config_file:
|
with open(f'{home}/.muell.yaml', 'r') as config_file:
|
||||||
config = yaml.safe_load(config_file)
|
config = yaml.load(config_file)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
@ -79,7 +75,6 @@ def read_file(jahr):
|
|||||||
''' Liest Daten aus muell<jahr>.csv und liefert ggf. Ergebnis zurück'''
|
''' Liest Daten aus muell<jahr>.csv und liefert ggf. Ergebnis zurück'''
|
||||||
|
|
||||||
antwort_liste = list()
|
antwort_liste = list()
|
||||||
headline = list()
|
|
||||||
try:
|
try:
|
||||||
with open(f'muell{jahr}.csv', 'r', encoding="latin1") as f:
|
with open(f'muell{jahr}.csv', 'r', encoding="latin1") as f:
|
||||||
csv_reader = csv.reader(f, delimiter=';')
|
csv_reader = csv.reader(f, delimiter=';')
|
||||||
@ -88,7 +83,6 @@ def read_file(jahr):
|
|||||||
for row in csv_reader:
|
for row in csv_reader:
|
||||||
if lines == 0:
|
if lines == 0:
|
||||||
# print(f'Column names are {", ".join(row)}')
|
# print(f'Column names are {", ".join(row)}')
|
||||||
headline = row
|
|
||||||
lines += 1
|
lines += 1
|
||||||
else:
|
else:
|
||||||
if isinstance(row, list):
|
if isinstance(row, list):
|
||||||
@ -96,7 +90,7 @@ def read_file(jahr):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return (antwort_liste, headline)
|
return antwort_liste
|
||||||
|
|
||||||
# Variablen
|
# Variablen
|
||||||
key = 'e21758b9c711463552fb9c70ac7d4273'
|
key = 'e21758b9c711463552fb9c70ac7d4273'
|
||||||
@ -117,7 +111,7 @@ postdata = {
|
|||||||
'f_id_abfalltyp_3': '187',
|
'f_id_abfalltyp_3': '187',
|
||||||
'f_id_abfalltyp_4': '169',
|
'f_id_abfalltyp_4': '169',
|
||||||
'f_abfallarten_index_max': '5',
|
'f_abfallarten_index_max': '5',
|
||||||
'f_abfallarten': '50,161,53,187',
|
'f_abfallarten': '50,161,53,187,169',
|
||||||
'f_zeitraum': zeitraum,
|
'f_zeitraum': zeitraum,
|
||||||
'f_export_als': export_als,
|
'f_export_als': export_als,
|
||||||
}
|
}
|
||||||
@ -127,8 +121,16 @@ headers = {
|
|||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
muell_arten = [
|
||||||
|
'Gelbe Tonne',
|
||||||
|
'Biomüll',
|
||||||
|
'Papiermüll',
|
||||||
|
'Restmüll',
|
||||||
|
'Schadstoffmobil',
|
||||||
|
]
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
(antwort_liste, headline) = read_file(current_year)
|
antwort_liste = read_file(current_year)
|
||||||
config = readConfig()
|
config = readConfig()
|
||||||
|
|
||||||
if not antwort_liste:
|
if not antwort_liste:
|
||||||
@ -147,38 +149,24 @@ if __name__ == '__main__':
|
|||||||
f = open(f'muell{current_year}.csv', 'wb')
|
f = open(f'muell{current_year}.csv', 'wb')
|
||||||
f.write(content)
|
f.write(content)
|
||||||
f.close()
|
f.close()
|
||||||
(antwort_liste, headline) = read_file(current_year)
|
antwort_liste = read_file(current_year)
|
||||||
|
|
||||||
tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y')
|
tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y')
|
||||||
index = set();
|
index = set();
|
||||||
for row in antwort_liste:
|
for row in antwort_liste:
|
||||||
try:
|
try:
|
||||||
if (row.count(tomorrow) > 1):
|
pos = row.index(tomorrow)
|
||||||
for i in range(len(row)):
|
if pos < 4:
|
||||||
if (row[i] == tomorrow and i < 4):
|
index.add(pos)
|
||||||
index.add(i)
|
|
||||||
else:
|
|
||||||
pos = row.index(tomorrow)
|
|
||||||
if pos < 4:
|
|
||||||
index.add(pos)
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
wird = 'wird' if len(index) < 2 else 'werden'
|
wird = 'wird' if len(index) < 2 else 'werden'
|
||||||
tonnen = []
|
tonnen = []
|
||||||
for pos in index:
|
for pos in index:
|
||||||
tonnen.append(headline[pos])
|
tonnen.append(muell_arten[pos])
|
||||||
|
|
||||||
if len(tonnen) > 0:
|
if len(tonnen) > 0:
|
||||||
tonnen = ' und '.join(tonnen)
|
tonnen = ' und '.join(tonnen)
|
||||||
# Jetzt den Telegram Bot ansprechen
|
# Jetzt den Bot ansprechen
|
||||||
try:
|
os.system(f'echo "Morgen {wird} {tonnen} abgeholt" | {config["pathBot"]} -u {config["tgReceiver"]}')
|
||||||
os.system(f'echo "Morgen {wird} {tonnen} abgeholt" | {config["telegram"]["pathBot"]} -u {config["telegram"]["tgReceiver"]}')
|
|
||||||
except Exception as e:
|
|
||||||
os.system(f'logger "Fehler Muellbot Telegram: {e}"')
|
|
||||||
|
|
||||||
# Signal Bot
|
|
||||||
try:
|
|
||||||
os.system(f'{config["signal"]["path"]} -a {config["signal"]["account"]} send -g {config["signal"]["group_id"]} -m "Morgen {wird} {tonnen} abgeholt"')
|
|
||||||
except Exception as e:
|
|
||||||
os.system(f'logger "Fehler Muellbot Signal: {e}"')
|
|
||||||
|
@ -1,69 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import struct
|
|
||||||
|
|
||||||
def read_proc_data(pid):
|
|
||||||
'''Liest Daten einer Prozess-ID aus /proc aus und zeigt diese an'''
|
|
||||||
|
|
||||||
proc_dir = '/proc/{0}'.format(pid)
|
|
||||||
|
|
||||||
if not os.path.exists(proc_dir):
|
|
||||||
return "Prozess mit PID {0} existiert nicht.".format(pid)
|
|
||||||
|
|
||||||
# Lese die Daten aus dem /proc-Verzeichnis
|
|
||||||
for filename in os.listdir(proc_dir):
|
|
||||||
file_path = os.path.join(proc_dir, filename)
|
|
||||||
|
|
||||||
# Ueberspringe Dateien, die keine Informationen enthalten
|
|
||||||
if filename in [".", "..", "task", "mem", "cwd", "exe", "pagemap"]:
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
if filename in ("environ", "cmdline"):
|
|
||||||
with open(file_path, "rb") as file:
|
|
||||||
environ_data = file.read()
|
|
||||||
print("{0}:".format(filename))
|
|
||||||
for line in environ_data.decode("utf-8", errors="replace").split("\x00"):
|
|
||||||
if line:
|
|
||||||
print(line)
|
|
||||||
|
|
||||||
print()
|
|
||||||
elif filename == "auxv":
|
|
||||||
with open(file_path, "rb") as file:
|
|
||||||
auxv_data = file.read()
|
|
||||||
print("{0}:".format(filename))
|
|
||||||
i = 0
|
|
||||||
while i < len(auxv_data):
|
|
||||||
entry_type, entry_value = struct.unpack("qq", auxv_data[i:i+16])
|
|
||||||
print("Type: {0}, Value: {1}".format(entry_type, entry_value))
|
|
||||||
i += 16
|
|
||||||
print()
|
|
||||||
else:
|
|
||||||
with open(file_path, "r") as file:
|
|
||||||
print("{0}:".format(filename))
|
|
||||||
for line in file:
|
|
||||||
line = line.rstrip("\n")
|
|
||||||
if line:
|
|
||||||
print(line)
|
|
||||||
print()
|
|
||||||
|
|
||||||
except (IOError, UnicodeDecodeError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
if len(sys.argv) != 2:
|
|
||||||
print("Bitte geben Sie die Prozess-ID (PID) als Argument an.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try:
|
|
||||||
pid = int(sys.argv[1])
|
|
||||||
except ValueError:
|
|
||||||
print("Ungueltige Prozess-ID (PID).")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
read_proc_data(pid)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user