aboutsummaryrefslogblamecommitdiffstats
path: root/kaminokumo
blob: c0a708bb3c15fc2c59616963c49818f431db0771 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                             
                 








                                                                               
                                                                                













                                                                                                
                                           
                            
                           
                
 

                                                                         


                                                                               
                                                                          
                     
                           

                                                                    

                                                                     
                     

                                                                     
                     

                                                                      


                                                                      





                              


                                          




                                                      
                          


                          
#!/usr/bin/python3

import argparse
import json
import code
import readline
import signal
import sys
import os
import requests
import urllib3
from time import sleep
from bs4 import BeautifulSoup
import subprocess

def SigHandler_SIGINT(signum, frame):
    print()
    sys.exit(0)

class Argparser(object):
    def __init__(self):
        parser = argparse.ArgumentParser()
        parser.add_argument("--url", type=str, nargs="+", help="url to scrape")
        parser.add_argument("--name", type=str, nargs="+", help="url to scrape")
        parser.add_argument("--dbg", action="store_true", help="debug", default=False)
        parser.add_argument("--demon", action="store_true", help="run as daemon", default=False)
        parser.add_argument("--slumber", type=int, help="how long the demon sleeps", default=60)
        self.args = parser.parse_args()

def mrg(url):
    requests.packages.urllib3.disable_warnings()
    resp = requests.get(url, verify=False)
    soup = BeautifulSoup(resp.text, "lxml")
    #print(resp.text)
    res = soup.select("dd")
    length = len(res[7].text.split(","))
    for split in res[7].text.split(","):
        if length == 1:
            if split.find("minutes") != -1:
                #print("mg")
                return True
    return False

def vocalize(sound):
    subprocess.call([os.path.expanduser("~")+"/scripts/voice.sh", sound])
###############################################################################
def premain(argparser):
    signal.signal(signal.SIGINT, SigHandler_SIGINT)
    url = json.load(open("/home/bloodstalker/extra/kaminokumo/data.json"))
    if mrg(url["1"]):
        print("mg", end="")
        vocalize(os.path.expanduser("~") + "/scripts/mila/mgup.ogg")
    if mrg(url["2"]):
        print ("obk", end="")
        vocalize(os.path.expanduser("~") + "/scripts/mila/obkup.ogg")
    if mrg(url["3"]):
        print ("ddd", end="")
        vocalize(os.path.expanduser("~") + "/scripts/mila/dddup.ogg")
    if mrg(url["4"]):
        print ("red", end="")
        vocalize(os.path.expanduser("~") + "/scripts/mila/annaup.ogg")
    if mrg(url["5"]):
        print ("ls", end="")
        vocalize(os.path.expanduser("~") + "/scripts/mila/lisaup.ogg")

def main():
    argparser = Argparser()
    if argparser.args.dbg:
        try:
            premain(argparser)
        except Exception as e:
            print(e.__doc__)
            if e.message: print(e.message)
            variables = globals().copy()
            variables.update(locals())
            shell = code.InteractiveConsole(variables)
            shell.interact(banner="DEBUG REPL")
    else:
        premain(argparser)

if __name__ == "__main__":
    main()