some more changes ...

This commit is contained in:
jnoack@itsblue.de 2019-02-06 17:58:33 +01:00
parent 6369ef3f52
commit 84a7065cbd

View file

@ -1,5 +1,6 @@
#!/usr/local/bin/python3 #!/usr/bin/python3
# this script is added to auto start of the pi zero in /etc/profiles ...
# this is the telegram version ... created with the @botFather of telegram # this is the telegram version ... created with the @botFather of telegram
# bot name: bully3 # bot name: bully3
@ -28,7 +29,7 @@ my_interpret1 = "unknownart1"
my_song2 = "unknownsong2" my_song2 = "unknownsong2"
my_interpret2 = "unknownart2" my_interpret2 = "unknownart2"
test = True test = False
if test: if test:
# bully4 # bully4
@ -97,6 +98,7 @@ def telegram_ahoy_reply(body):
global nextchecktime global nextchecktime
global starttime global starttime
global auto_check_for_is1_is2 global auto_check_for_is1_is2
global send_false_alarms
if (re.search("^list$", body, re.IGNORECASE) is not None) | (re.search("^l$", body, re.IGNORECASE) is not None): if (re.search("^list$", body, re.IGNORECASE) is not None) | (re.search("^l$", body, re.IGNORECASE) is not None):
soup_page(15) soup_page(15)
@ -156,7 +158,7 @@ def telegram_ahoy_reply(body):
if send_false_alarms: if send_false_alarms:
message = message + "Sending false alarms: ON\n" message = message + "Sending false alarms: ON\n"
else: else:
message = message + "Sending false alarms: ON\n" message = message + "Sending false alarms: OFF\n"
message = message + "Last overall checktime: " + fullcurrenttime + "\n" message = message + "Last overall checktime: " + fullcurrenttime + "\n"
message = message + "Last automatic checktime: " + lastwwwparsetime + "\n" message = message + "Last automatic checktime: " + lastwwwparsetime + "\n"
message = message + "Next checktime: " + nextchecktime + "\n" message = message + "Next checktime: " + nextchecktime + "\n"
@ -180,26 +182,25 @@ def telegram_ahoy_reply(body):
message = message + "SWITCHED ON now." message = message + "SWITCHED ON now."
else: else:
if re.search("^m", body, re.IGNORECASE): if re.search("^m", body, re.IGNORECASE):
message = "Sending even false alarms:\n" message = "Sending even false alarms:\n"
if send_false_alarms: if send_false_alarms:
send_false_alarms = False send_false_alarms = False
message = message + "SWITCHED OFF now." message = message + "SWITCHED OFF now."
else: else:
send_false_alarms = True send_false_alarms = True
message = message + "SWITCHED ON now." message = message + "SWITCHED ON now."
else: else:
message = "Send: \n\n'list' or 'l' for latest playlist.\n '?' for songs/title looking for.\n 's1=songname' to change song1.\n" message = "Send: \n\n'list' or 'l' for latest playlist.\n '?' for songs/title looking for.\n 's1=songname' to change song1.\n"
message = message + " 'i1=artist' to change interpret1.\n 's2=songname' to change song2.\n 'i2=artist' to change interpret2.\n" message = message + " 'i1=artist' to change interpret1.\n 's2=songname' to change song2.\n 'i2=artist' to change interpret2.\n"
message = message + " 'is1=artist,song to change #1 \n 'is2=artist,song to change #2 \n " message = message + " 'is1=artist,song to change #1 \n 'is2=artist,song to change #2 \n "
message = message + " 'w' write i&s to file.\n 'r' read i&s from file\n" message = message + " 'w' write i&s to file.\n 'r' read i&s from file\n"
message = message + " 'f' shows found songs.\n 'c' clears list with found songs\n" message = message + " 'f' shows found songs.\n 'c' clears list with found songs\n"
message = message + " 's' shows statistics.\n 'g' gets song1,2 and interprets1,2\n" message = message + " 's' shows statistics.\n 'g' gets song1,2 and interprets1,2\n"
message = message + " 'a' toggle auto get is1,is2\n 'm' toggle false alarms\n" message = message + " 'a' toggle auto get is1,is2\n 'm' toggle false alarms\n"
return message return message
def write_to_file(): def write_to_file():
global file_name global file_name
global song1, interpret1, song2, interpret2 global song1, interpret1, song2, interpret2
@ -487,7 +488,7 @@ def remove_signs_from_string(string):
string = string.replace("´", "") string = string.replace("´", "")
string = string.replace("", "") string = string.replace("", "")
string = re.sub(' +', ' ', string) string = re.sub(' +', ' ', string)
string = string.strip() string = string.strip(" ")
return string return string
def soup_2songs_page(): def soup_2songs_page():
@ -542,13 +543,13 @@ def soup_2songs_page():
isstr = re.search(" *(.+?) *: *(.+?)$", item_text) isstr = re.search(" *(.+?) *: *(.+?)$", item_text)
if isstr: if isstr:
if is_nr == 1: if is_nr == 1:
iinterpret1 = isstr.group(1) iinterpret1 = remove_signs_from_string(isstr.group(1))
isong1 = isstr.group(2) isong1 = remove_signs_from_string(isstr.group(2))
#print("Interpret1 '" + iinterpret1 + "' - Song1 '" + isong1 + "'") #print("Interpret1 '" + iinterpret1 + "' - Song1 '" + isong1 + "'")
is_nr = is_nr + 1 is_nr = is_nr + 1
elif is_nr == 2 : elif is_nr == 2 :
iinterpret2 = isstr.group(1) iinterpret2 = remove_signs_from_string(isstr.group(1))
isong2 = isstr.group(2) isong2 = remove_signs_from_string(isstr.group(2))
#print("Interpret2 '" + iinterpret2 + "' - Song2 '" + isong2 + "'") #print("Interpret2 '" + iinterpret2 + "' - Song2 '" + isong2 + "'")
is_nr = is_nr + 1 is_nr = is_nr + 1
if parse_error == True: if parse_error == True:
@ -780,14 +781,15 @@ bully3_bot = telegram.Bot(telegram_token)
if __name__ == "__main__": if __name__ == "__main__":
try: try:
scanwwthread = scanThread(1,"parse_www")
scanwwthread.start()
telegramthread = telegramThread(1,"telegram_bot") telegramthread = telegramThread(1,"telegram_bot")
telegramthread.start() telegramthread.start()
scanwwthread = scanThread(1,"parse_www")
scanwwthread.start()
except KeyboardInterrupt: except KeyboardInterrupt:
print("Detected CTRL-C ... stopping the process. Please wait ...\n") print("Detected CTRL-C ... stopping the process. Please wait ...\n")
run_thread = 0 run_thread = 0
wait(10)
scanwwthread.join() scanwwthread.join()
telegramthread.join() telegramthread.join()
sys.exit() sys.exit()