Ejemplo n.º 1
0
def openid():
    Code = request.args.get('code')  # 获取Code
    OpenId.openid.setcode(OpenId, Code)     # 传入COde
    OpenId.openid.openid(OpenId)    # 执行获取Openid
    if not Select.openid(OpenId.openid.getopenid(OpenId)):  # 查询数据库有没有openid
        Insert.openid(OpenId.openid.getopenid(OpenId))
        OpenId.openid.mkdir(OpenId)
    return 'ok'
Ejemplo n.º 2
0
def insert():
    import Insert
    post_data = request.json
    if 'sig' in post_data:
        return Insert.Insert(None, None, post_data['sig'])
    else:
        data = post_data['data']
        count = post_data['count']
        return Insert.Insert(data, count)
Ejemplo n.º 3
0
def on_closing():
    try:
        Scr.end(scraper)
    except Exception:
        pass
    try:
        Ins.end(inserter)
    except Exception:
        pass
    window.destroy()
Ejemplo n.º 4
0
async def ws_handler(websocket, path):
    #open connection w/client, get data from them, and send back that data
    print("client connected")
    clientstring = await websocket.recv()
    print(clientstring, "received")

    #parse the JSON string received... temporary version, and insert mood to database
    mood = Insert.TempJSONparser(clientstring)
    Insert.insertmood(mood)

    #later: message will reflect status of program, be in JSON format, etc
    response = "The server has received your message"  #returned JSON data from parser
    await websocket.send(response)
Ejemplo n.º 5
0
 def Guardar(self):
     idDocente = BdUsuario.BdUsurio.Docente
     i = Insert.Insert()
     d = self.varmenuD.get()
     horaI = self.varmenuH.get()[0:5]
     horaF = self.varmenuH.get()[6:11]
     i.addReservacion(d[0:1], idDocente, horaI, horaF)
Ejemplo n.º 6
0
def populate_movies(engine, latest_movie_id):
    conn = engine.connect()

    with open('{}/{}.json'.format('temp', PATHS[0])) as f:
        lines = f.readlines()

        start_time = time.time()
        request_count = 0

        try:
            for line in lines:
                movie_id = json.loads(line)['id']

                if movie_id > latest_movie_id:
                    url = 'https://api.themoviedb.org/3/movie/{}?api_key={}&language=en-US&append_to_response=videos'.format(
                        movie_id, API_KEY)

                    req = requests.get(url)
                    request_count += 1
                    print(url)

                    if request_count >= 38:
                        duration = time.time() - start_time
                        if duration < 10:
                            time.sleep(10 - duration)

                        start_time = time.time()
                        request_count = 0

                    if (req.status_code == 200):
                        res = json.loads(req.text)

                        conn.execute(Insert.insert_movie(res))

                        for genre in res['genres']:
                            conn.execute(
                                Insert.insert_movie_genre(genre, movie_id))

                        for video in res['videos']['results']:
                            conn.execute(Insert.insert_video(video, movie_id))
                    else:
                        print(req.text)
        except:
            print(traceback.print_exc())
        finally:
            f.close()
            conn.close()
Ejemplo n.º 7
0
def save():
    nazwa = nazwa_input.get()
    opis = opis_input.get(1.0, END)
    miasto = miasto_input.get()
    adres = adres_input.get()
    fb = fb_input.get()
    ig = ig_input.get()
    email = email_input.get()
    tel = tel_input.get()
    web = web_input.get()

    if fb and nazwa and miasto and adres:
        place = Place(nazwa, opis, miasto, adres, fb, ig, email, tel, web)
        Ins.insert(place, inserter)
    else:
        fb_input.delete(0, END)
        fb_input.insert(INSERT, "Brak inforamcji.")
Ejemplo n.º 8
0
def populate_person(engine, latest_person_id):
    conn = engine.connect()

    with open('{}/{}.json'.format('temp', PATHS[2])) as f:
        start_time = time.time()
        request_count = 0

        try:
            for line in f.readlines():
                person_id = json.loads(line)['id']

                if person_id > latest_person_id:
                    url = 'https://api.themoviedb.org/3/person/{}?api_key={}&language=en-US&append_to_response=movie_credits'.format(
                        person_id, API_KEY)

                    req = requests.get(url)
                    request_count += 1
                    print(url)

                    if request_count >= 38:
                        duration = time.time() - start_time
                        if duration < 10:
                            time.sleep(10 - duration)

                        start_time = time.time()
                        request_count = 0

                    if (req.status_code == 200):
                        res = json.loads(req.text)

                        conn.execute(Insert.insert_person(res))

                        for cast in res['movie_credits']['cast']:
                            conn.execute(
                                Insert.insert_movie_cast(cast, person_id))

                        for crew in res['movie_credits']['crew']:
                            conn.execute(
                                Insert.insert_movie_crew(crew, person_id))
                    else:
                        print(req.text)
        except:
            print(traceback.print_exc())
        finally:
            f.close()
            conn.close()
Ejemplo n.º 9
0
def populate_collection(engine, latest_movie_collection_id):
    conn = engine.connect()

    with open('{}/{}.json'.format('temp', PATHS[1])) as f:
        lines = f.readlines()

        start_time = time.time()
        request_count = 0

        try:
            for line in lines:
                collection_id = json.loads(line)['id']

                if collection_id > latest_movie_collection_id:
                    url = 'https://api.themoviedb.org/3/collection/{}?api_key={}&language=en-US'.format(
                        collection_id, API_KEY)

                    req = requests.get(url)
                    request_count += 1
                    print(url)

                    if request_count >= 38:
                        duration = time.time() - start_time
                        if duration < 10:
                            time.sleep(10 - duration)

                        start_time = time.time()
                        request_count = 0

                    if (req.status_code == 200):
                        res = json.loads(req.text)

                        conn.execute(Insert.insert_movie_series(res))

                        for movie in res['parts']:
                            conn.execute(
                                Insert.insert_part_of_series(res, movie['id']))
                    else:
                        print(req.text)
        except:
            print(traceback.print_exc())
        finally:
            f.close()
            conn.close()
Ejemplo n.º 10
0
    def Guardar(self):

        idDocente = BdUsuario.BdUsurio.Docente
        i = Insert.Insert()
        d = self.b.varmenuD.get()
        horaI = self.b.varmenuH.get()[0:5]
        horaF = self.b.varmenuH.get()[6:11]
        print(d[0:1])
        print(idDocente)
        print(horaI)
        print(horaF)
        i.addReservacion(d[0:1], idDocente, horaI, horaF)
        self.pon()
Ejemplo n.º 11
0
    def crea(self):
        i = Insert.Insert()
        try:
            i.insertarNoticia(self.filename,
                              self.cuadroTxt.get("1.0", 'end-1c'),
                              BdUsuario.BdUsurio.Adminstrador,
                              self.titulo.get())
            print("insercion correcta")
            self.cuadroTxt.delete("1.0", 'end-1c')
            self.titulo.delete(0, END)
            self.label.config(image="")
            self.label.place_forget()

        except:
            MessageBox.showerror("Error", "Tienes que llenar todos los campos")
Ejemplo n.º 12
0
    web = web_input.get()

    if fb and nazwa and miasto and adres:
        place = Place(nazwa, opis, miasto, adres, fb, ig, email, tel, web)
        Ins.insert(place, inserter)
    else:
        fb_input.delete(0, END)
        fb_input.insert(INSERT, "Brak inforamcji.")


window = Tk()
window.title("Facebook Gastronomy Scraper")
window.resizable(0, 0)
window.protocol("WM_DELETE_WINDOW", on_closing)
scraper = Scr.open_driver()
inserter = Ins.login()

top = Frame(window)
top.grid(row=0, column=0)

Label(top, text="Facebook: ").grid(row=0, column=0, padx=5, pady=15)

fb_input = Entry(top, width=40)
fb_input.grid(row=0, column=1, padx=5, pady=15)

Button(top, text="Pobierz", width=7, command=scrape).grid(
    row=0, column=2, padx=5, pady=15)

images = Frame(window)
images.grid(row=1, column=1)
Ejemplo n.º 13
0
kafka_twitter_topic = os.environ["kafka_twitter_topic"]
docker_kafka_port = os.environ["docker_kafka_port"]
docker_kafka_adress = os.environ["docker_kafka_adress"]

if __name__ == "__main__":
    for i in range(15):
        try:
            consumer = KafkaConsumer(
                kafka_twitter_topic,
                bootstrap_servers=[
                    f'{docker_kafka_adress}:{docker_kafka_port}'
                ],
                auto_offset_reset='earliest',
                enable_auto_commit=True,
                group_id=None,
                value_deserializer=lambda x: loads(x.decode('utf-8')),
            )
            i = 15
        except:
            # Wait for kafka to be up
            time.sleep(2)
            logging.warn("Cannot connect to Kafka. Retrying in 2 seconds")

    logging.info('Connecting to database')
    con, table = Insert.init_table()

    for message in consumer:
        if "text" in message.value:
            logging.info(f"received message : {message.value['text']}")
            Insert.insertTweet(con, table, message.value)
Ejemplo n.º 14
0
import ConnectDB, Insert, CheckInv, CreateInvoice, getpass, cls
cls.clr()
print("----------------Login--------------------")
usr_name = input("Username : "******"Invalid username or password!!!")
else:
    cursor.execute("USE Project;")
    cls.clr()
    print("1. Insert values into database : ")
    print("2. Check inventory for items : ")
    print("3. Create Invoice : ")
    opt = int(input("Select an option : "))
    if opt == 1:
        Insert.Insert(db, cursor)
    elif opt == 2:
        CheckInv.CheckInv(cursor)
    elif opt == 3:
        CreateInvoice.Invoice(db, cursor)
    else:
        print("Wrong Option....... Exiting")
        ConnectDB.disconnect(db)