74 lines
1.8 KiB
Python
74 lines
1.8 KiB
Python
import Invoice, Tap, Video
|
|
import subprocess, os, time, threading
|
|
from configparser import ConfigParser
|
|
from events import Events
|
|
|
|
events = Events()
|
|
config = ConfigParser(allow_no_value=True)
|
|
config.read('configs/config.beer')
|
|
INTERVAL = config.get('LNBITS', 'check_interval')
|
|
videoThread = threading.Thread(target=Video.PlayRandomVideo)
|
|
|
|
def KillVLC():
|
|
try:
|
|
os.system("sudo killall vlc > /dev/null 2>&1")
|
|
except:
|
|
pass
|
|
|
|
def SetStatus(active):
|
|
config.read('configs/config.beer')
|
|
config.set('LIVE', 'beertap_active', str(active))
|
|
config.write
|
|
with open('configs/config.beer', 'w') as configfile:
|
|
config.write(configfile)
|
|
|
|
def Kill():
|
|
SetStatus(False)
|
|
Tap.CloseTapManually()
|
|
KillVLC()
|
|
|
|
def GenerateInvoiceAndShowQRCode():
|
|
paid = False
|
|
Invoice.Generate()
|
|
Video.ShowQRCode()
|
|
while not paid:
|
|
time.sleep(float(INTERVAL))
|
|
paid = Invoice.CheckPaymentStatus()
|
|
if paid:
|
|
Invoice.ResetInvoice()
|
|
StartTapping()
|
|
|
|
def StartTapping():
|
|
#Run BeerRoutine
|
|
print("Invoice paid - Start TappingProcess!\n")
|
|
#Show Countdown
|
|
Video.PlayCountdown()
|
|
#Play Random Video in a thread
|
|
videoThread.start()
|
|
#Start Tapping Process
|
|
Tap.StartTapping()
|
|
|
|
def TappingCompleted():
|
|
print("\nTapping Process Completed")
|
|
time.sleep(1)
|
|
if videoThread.is_alive():
|
|
videoThread.join()
|
|
Kill()
|
|
exit()
|
|
#system will restart Beertap.service
|
|
|
|
#TappingCompleted gets triggered by Tap.py
|
|
events.on_tapping_completed += TappingCompleted
|
|
|
|
def main():
|
|
try:
|
|
SetStatus(True)
|
|
Tap.CloseTapManually()
|
|
GenerateInvoiceAndShowQRCode()
|
|
except KeyboardInterrupt:
|
|
Kill()
|
|
print("\nkeyboardinterrupt detected")
|
|
|
|
if __name__ == '__main__':
|
|
main()
|