Beispiel #1
0
def add_provider(db_enabled, lastname, firstname, credentials, addr1, addr2, city, zipcode, state,latitude, longitude):

    # if db is enabled, then open a session with the database
    if db_enabled:
        session = Session()

        # create an instance of the Provider type
        provider = Provider(lastname=lastname, firstname=firstname,
                            credentials=credentials, addr1=addr1, addr2=addr2,
                            city=city, zipcode=zipcode,state=state,
                            latitude=latitude, longitude=longitude)


    #To check if the record already exists in database 
    p = select([Provider.firstname]).where(Provider.firstname+Provider.lastname+Provider.credentials
                                           +Provider.addr1+Provider.addr2 == firstname+lastname+credentials+addr1+addr2)

    res = session.execute(p)
    prov_data = res.fetchone()
    session.close()    

    #To check if record exists, then this step will be skipped
    if not(prov_data):
        session = Session()
        # To fetch the Geographical coordinates from Zip_geotable 
        z = select([Zip_geo.latitude, Zip_geo.longitude]).where(Zip_geo.zipcode == zipcode)
        result = session.execute(z)
        geo_data = result.fetchone()

        if geo_data:
            latitude = geo_data.latitude
            longitude= geo_data.longitude
            #print db_enabled, lastname, firstname, credentials, addr1, addr2, city, zipcode, state,latitude, longitude
            
            
            # create an instance of the Provider type
            provider = Provider(lastname=lastname, firstname=firstname,
                                credentials=credentials, addr1=addr1, addr2=addr2,
                                city=city, zipcode=zipcode,state=state,
                                latitude=latitude, longitude=longitude)            
            

            # if db is enabled, then add to the recordset and commit the txn
            session.add(provider)
            session.commit()
            session.close()
                
    return provider
def get(username):
    session = Session()
    try:
        return session.query(PlayerData).filter(
            PlayerData.name == username).one()
    except:
        return None
Beispiel #3
0
 def __init__(self, app):
     global session
     session = Session()
     self.app = app
     self.db = Database()
     self.db.destroy()
     self.db.init()
def do_command (task_id) :
    try :
        task_res = get_task_by_id(task_id)
        if task_res["status"] != 0 :
            return {"status":-1 , "val":None}
        task = task_res["val"]["task"]
        group_id = script_group = task_res["val"]["script_group"].id
        server_group = task_res["val"]["server_group"]
        scripts = get_scripts_by_group_id(group_id)["val"]
        script_list = []
        for script in scripts :
            script_list.append(str(script.location))
        server_list = []
        for server in server_group.servers :
            server_list.append(server.dump())
        if script_list == [] or server_list == [] :
            return {"status":-1 , "val":None}
        task_to_do = {"scripts":script_list , "servers":server_list}
        success_array , key_code_list = upload_remotefile.do_task(task_to_do)
        session = Session()
        taskStatus = session.query(TaskStatus).filter(TaskStatus.task_id == task_id).first()
        if taskStatus == None :
            taskStatus = TaskStatus(task_id , json.dumps(success_array) , json.dumps(key_code_list))
            taskStatus_id = taskStatus.save_return_id(session)
        else :
            taskStatus.success_array = json.dumps(success_array)
            taskStatus.key_code_list = json.dumps(key_code_list)
            taskStatus_id = taskStatus.id
            taskStatus.save(session)
        session.close()
        return {"status":0 , "val":taskStatus_id}
    except Exception , msginfo :
        return {"status":-1 , "val":msginfo}
def update_position(group_id , json_str) :
    try :
        session = Session()
        position_list = json_str.split('|')
        position_list.remove(position_list[len(position_list)-1])
        for i in range(len(position_list)) :
            position_list[i] = int(str(position_list[i]))
        sorted_script = session.query(Sorted_Script).filter(Sorted_Script.group_id == group_id).first()
        sorted_array = json.loads(sorted_script.sorted_array)
        check = True
        for item in position_list :
            if item not in sorted_array :
                check = False
                break
        if len(position_list) != len(sorted_array) :
            check = False
        if check == True :
            sorted_script.sorted_array = json.dumps(position_list)
            sorted_script.save(session)
            return {"status":0 , "val":None}
        else :
            return {"status":-1 , "val":None}
   
    except Exception , msginfo :
        return {"status":-1 , "val":msginfo}
Beispiel #6
0
 def __init__(self, schema_path='schema.json'):
     self.session = Session()
     self.genres_cache = dict()
     self.tags_cache = dict()
     self.staffs_cache = dict()
     schema = json.load(open(schema_path, 'r'))
     self.validator = jsonschema.Draft4Validator(schema)
Beispiel #7
0
def train(iterations=80000, summary_interval=100, batch=32):
    tf.logging.set_verbosity(tf.logging.INFO)
    placeholders = create_placeholders()
    global_step, network_a, network_b = get_network(*placeholders[-4:], placeholders[5])
    with Session(True, True, global_step) as sess:
        with Driver() as driver:
            try:
                last_save = timer()
                array = []
                buffer = score_buffer()
                step = 0
                time = 1
                for _ in range(iterations):
                    if len(array) < batch*10:
                        get_input(driver, sess.session, network_a, network_b, placeholders, buffer, array)
                    pre = timer()
                    _, aloss, step = sess.session.run([network_a.trainer, network_a.loss, global_step], feed_dict=get_batch_feed(array, placeholders, batch, batch//2))
                    _, bloss = sess.session.run([network_b.trainer, network_b.loss], feed_dict=get_batch_feed(array, placeholders, batch, batch//2))
                    time = 0.9*time + 0.11 *(timer()-pre)
                    if step%10 == 0:
                        print("Training step: %i, Loss A: %.3f, Loss B: %.3f (%.2f s)  "%(step, aloss, bloss, time), end='\r')
                    if step%summary_interval == 0:
                        sess.save_summary(step, get_batch_feed(array, placeholders, batch, batch//2))
                        print()
                    if timer() - last_save > 1800:
                        sess.save_network()
                        last_save = timer()
            except (KeyboardInterrupt, StopIteration):
                print("\nStopping the training")
Beispiel #8
0
def insert_db_weather(weather_values):
    """Function for inserting scraped data from Weather API into database"""
    session = Session()
    new_data = Weather(
        coord_lon=weather_values["coord"]["lon"],
        coord_lat=weather_values["coord"]["lat"],
        weather_id=weather_values["weather"][0]["id"],
        weather_main=weather_values["weather"][0]["main"],
        weather_description=weather_values["weather"][0]["description"],
        weather_icon=weather_values["weather"][0]["icon"],
        base=weather_values["base"],
        main_temp=weather_values["main"]["temp"],
        main_pressure=weather_values["main"]["pressure"],
        main_humidity=weather_values["main"]["humidity"],
        main_temp_min=weather_values["main"]["temp_min"],
        main_temp_max=weather_values["main"]["temp_max"],
        visibility=weather_values["visibility"],
        wind_speed=weather_values["wind"]["speed"],
        wind_deg=weather_values["wind"]["deg"],
        clouds_all=weather_values["clouds"]["all"],
        dt=datetime.fromtimestamp(weather_values["dt"]),
        sys_type=weather_values["sys"]["type"],
        sys_id=weather_values["sys"]["id"],
        sys_message=weather_values["sys"]["message"],
        sys_country=weather_values["sys"]["country"],
        sys_sunrise=datetime.fromtimestamp(weather_values["sys"]["sunrise"]),
        sys_sunset=datetime.fromtimestamp(weather_values["sys"]["sunset"]),
        city_id=weather_values["id"],
        city_name=weather_values["name"],
        cod=weather_values["cod"])
    session.add(new_data)
    session.commit()
    session.close()
Beispiel #9
0
def updateAllPlaylist():
    print("-" * 10, "Updating all playlists", "-" * 10)
    session = Session()
    playlists = session.query(playlistDB).all()
    for playlist in playlists:
        print("[*] Playlist name:", playlist.name)

        songsList = getPlaylist(playlist.nid)["playlist"]["trackIds"]
        idList = [i["id"] for i in songsList]

        DBsongsList = session.query(songDB.nid).filter(
            songDB.playlist.contains(playlist.name)).all()
        DBidList = [i[0] for i in DBsongsList]

        addIdList = list(set(idList) - set(DBidList))
        delIdList = list(set(DBidList) - set(idList))
        delDataList = session.query(songDB).filter(
            songDB.nid.in_(delIdList)).all()

        if addIdList:
            print(" |  Adding new songs...")
            record = addNewSongs(playlist.name, addIdList)
            print(" |  Total {} songs, {} new songs added, {} songs modified.".
                  format(len(idList), record["add"], record["modify"]))
        if delIdList:
            print(" |  Removing deleted songs...")
            removePlaylistInSongDB(delDataList)
        if not addIdList or delIdList:
            print(" |  Nothing to do.")
    print("[*] All done.")

    print("")  # 好看
Beispiel #10
0
    def get_parlamentar(self, _name, scope=None):
        session = Session()

        if scope is None:
            parlamentar = session.query(Parlamentar).filter_by(name=_name)[0]
            mandato = session.query(Mandato).filter_by(
                parlamentar_id=parlamentar.id)[0]
            ex = session.query(Exercicio).filter_by(
                parlamentar_id=parlamentar.id)
            exercicios = [e for e in ex]
            dictp = dict(parlamentar=parlamentar,
                         mandato=mandato,
                         exercicios=exercicios)
        else:
            qry = session.query(Parlamentar).filter(
                Parlamentar.name.like('%' + _name + '%')).all()
            dictp = []
            for p in qry:
                dict_temp = dict()
                dict_temp['parlamentar'] = p
                dict_temp['mandato'] = session.query(Mandato).filter_by(
                    parlamentar_id=p.id)
                dictp.append(dict_temp)

        return dictp
 def mythicspoiler_crawl(self, context):
     local_session = Session()
     cards = self.ms.get_cards_from_news()
     for page, image_url, card_set in cards:
         if image_url not in self.mythicspoiler_futur_cards_url:
             config.bot_logger.info(
                 f"New card detected from mythicspoiler: {page}")
             # New card detected on mythic spoiler, save it
             self.mythicspoiler_futur_cards_url.append(image_url)
             # Try to see if it has already been spoiled
             im = Image(location=image_url,
                        descr=im_utils.descript_image(image_url))
             if not self.sd.is_duplicate(
                     im, [s.image.descr for s in self.spoiled]):
                 # card not recognize as a duplicate, save then publish it
                 local_session.add(im)
                 sp = Spoiler(url=page,
                              source=SpoilerSource.MYTHICSPOILER.value,
                              source_id=SpoilerSource.MYTHICSPOILER.value,
                              found_at=datetime.now(),
                              set_code=card_set)
                 sp.image = im
                 sp.set = local_session.query(Set).filter(
                     Set.code == card_set).first()
                 local_session.add(sp)
                 self.spoiled.append(sp)
                 self.send_spoiler(sp, context)
     local_session.commit()
    def __init__(self):
        # init config
        self.config = RawConfigParser()
        self.config.read_file(codecs.open('config.ini', encoding='utf8'))

        logger.info('Configuration loaded')
        # init database
        self.session = Session()

        # init Qt windows
        self.app = QApplication(sys.argv)

        self.window = QMainWindow()

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self.window)

        self.update_mpc_plugin_list()

        self.ui.mpc_title_frame_title.setText(
            self.config['options']['project_name'])
        self.window.setWindowTitle(self.config['options']['project_name'])
        self.ui.mpc_btn_import.clicked.connect(self.import_plugin)
        self.ui.mpc_plugins_list.itemClicked.connect(self.load_plugin_by_item)

        self.ui.ps_btn_back.clicked.connect(self.go_to_main_screen)
        self.ui.ps_delete_plugin_btn.clicked.connect(self.delete_plugin)

        self.go_to_main_screen()
        self.window.show()

        # todo: Delete this part before first release
        self.garbage_test_code()
        sys.exit(self.app.exec_())
 def scryfall_cards_crawl(self, context):
     local_session = Session()
     futur_cards = scryfall.get_futur_cards()
     for futur_card in futur_cards:
         if not futur_card.get("id") in self.scryfall_futur_cards_id:
             config.bot_logger.info(
                 f"New card detected from scryfall: {futur_card.get('name')}"
             )
             # New card detected, add it to scryfall list
             self.scryfall_futur_cards_id.append(futur_card.get("id"))
             # Try to see if it has already been spoiled
             for i_url in scryfall.get_image_urls(futur_card):
                 im = Image(location=i_url,
                            descr=im_utils.descript_image(i_url))
                 if not self.sd.is_duplicate(
                         im, [s.image.descr for s in self.spoiled]):
                     # card not recognize as a duplicate, save then publish it
                     local_session.add(im)
                     sp = Spoiler(url=scryfall.get_card_url(futur_card),
                                  source=SpoilerSource.SCRYFALL.value,
                                  source_id=futur_card.get("id"),
                                  found_at=datetime.now(),
                                  set_code=futur_card.get("set_code", None))
                     sp.image = im
                     local_session.add(sp)
                     self.spoiled.append(sp)
                     sp.set = local_session.query(Set).filter(
                         Set.code == futur_card.get("set_code")).first()
                     self.send_spoiler(sp, context)
     local_session.commit()
Beispiel #14
0
    def get(self):
        try:
            session = Session()
            uuid = request.headers["GreenList-User-Id"]
            user = UserController().get_user_by_id(uuid, session)
            if not user:
                abort(401)
            products = (
                SuggestionController().get_suboptimal_products(session))
            result = []
            for product in products:
                product_json = self.product_to_json(product)

                suggestions = SuggestionController().get_suggestions(
                    user, product, session)

                alternatives = [
                    self.suggestion_to_json(suggestion)
                    for suggestion in suggestions
                ]

                product_json.update({'alternatives': alternatives})
                result.append(product_json)
            return result
        finally:
            session.close()
Beispiel #15
0
def create_session(user, is_trusted):
    """
    Perform user authentication User.password and role activations.
    This method must be called once per user prior to calling other methods within this module. 
    The successful result is Session that contains target user's RBAC User.roles.
    
    This API will...

    * authenticate user password if trusted == false.
    * evaluate temporal Constraint(s) on User and UserRoles.
    * process selective role activations into User RBAC Session User.roles.
    * return a Session containing Session.user, Session.user.roles
    
    required parameters:
    user.uid - maps to INetOrgPerson uid
    is_trusted - boolean, if 'True', authentication is skipped (password not checked)     
    """
    __validate_user(user)
    session = Session()
    if is_trusted is False:
        # failure throws exception:
        userdao.authenticate(user)
        session.is_authenticated = True
    entity = userdao.read(user)
    result = __validate_constraint(entity.constraint)
    if result is not SUCCESS:
        raise FortressError(
            'create_session constraint validation failed uid:' + entity.uid,
            result)
    __validate_role_constraints(entity)
    session.user = entity
    return session
def create_server(username , password , host_address , host_port , script_location) :
    try :
        session = Session()
        new_server = Server(username , password , host_address , host_port , script_location)
        server_id = new_server.save_return_id(session)
        return {"status":0 , "val":server_id}
    except Exception , msginfo :
        return {"status":-1 , "val":msginfo}
Beispiel #17
0
def get_station():
    session = Session()
    stations = []
    rows = session.execute("select * from station;")
    for row in rows:
        stations.append(dict(row))
    session.close()
    return jsonify(stations=stations)
Beispiel #18
0
    def get(self):
        cmt_id = int(self.get_argument('cmt_id'))

        session = Session()
        comment = session.query(Comment).get(cmt_id)
        user = session.query(User).get(comment.user_id)

        self.render('reply_comment.html', comment=comment, user=user)
def new(user):
    new_key = token_urlsafe(32)
    session = Session(new_key, user)
    # rare
    while new_key in sessions:
        new_key = token_urlsafe(32)
    sessions[new_key] = session
    return session
Beispiel #20
0
def showAllPlaylist():
    session = Session()
    print("-" * 10, "Show all playlists.", "-" * 10)
    playlists = session.query(playlistDB).all()
    print("{}\t{}".format("名字", "网易云id"))
    for playlist in playlists:
        print("{}\t{}".format(playlist.name, playlist.nid))
    print("")  # 好看
def get_script_by_id(script_id) :
    try :
        session = Session()
        script = session.query(Script).filter(Script.id == script_id).first()
        if script == None :
            return {"status":-1 , "val":None}
        return {"status":0 , "val":script}
    except Exception , msginfo :
        return {"status": -1 , "val":msginfo}
def get_script_group_list() :
    try :
        session = Session()
        group_list = session.query(ScriptGroup).all()
        if group_list == None or len(group_list) == 0 :
            return {"status":-1 , "val":None}
        return {"status":0 , "val":group_list}
    except Exception , msginfo :
        return {"status": -1 , "val":msginfo}
Beispiel #23
0
 def get_stored_range(x_min, x_max, y_min, y_max):
     session = Session()
     
     value = session.query(DataMap).filter(and_(DataMap.x >= x_min, DataMap.x <= x_max, \
                                                DataMap.y >= y_min, DataMap.y <= y_max)).all() 
     ret_val = {}
     for tile in value:
         ret_val[(tile.x, tile.y)] = tile.value
     return ret_val
Beispiel #24
0
def save_data_to_post_data(all_posts_url):
    # Функция сохранения данных в таблице post_data
    session = Session()
    for elements in all_posts_url:
        c1 = Post_data(group_id=elements[0],
                       post_id=elements[1],
                       post_text=elements[2])
        session.add(c1)
    session.commit()
Beispiel #25
0
def contest(contest_id):
    session = Session()
    contest = session.query(Contest).filter(Contest.contest_id == contest_id).first()
    tasks = session.query(Task).filter(Task.contest_id == contest_id).all()
    results = session.query(Result).filter(Result.contest_id == contest_id).all()
    result_hash = {(r.user_id, r.problem_id): r for r in results}
    user_ids = {r.user_id for r in results}
    return render_template('contest.jinja2', contest=contest, tasks=tasks,
                           result_hash=result_hash, user_ids=user_ids)
def get_server_by_id(server_id) :
    try :
        session = Session()
        server = session.query(Server).filter(Server.id == server_id).first()
        if server == None :
            return {"status":-1 , "val":None}
        return {"status":0 , "val":server}
    except Exception , msginfo :
        return {"status": -1 , "val":msginfo}
Beispiel #27
0
def save_data_to_comment_data(all_comments):
    # Функция сохранения данных в таблице comment_data
    session = Session()
    for elements in all_comments:
        c1 = Comment_data(post_id=elements[0],
                          comment_id=elements[1],
                          comment_text=elements[2],
                          likes=elements[3])
        session.add(c1)
    session.commit()
Beispiel #28
0
def showAllSongs():
    session = Session()
    print("-" * 10, "Show all songs.", "-" * 10)
    print("{}\t{}\t{}".format("序号", "名字", "艺人", "专辑", "播放列表", "网易云id"))
    for song in songs:
        print(song.to_dict())
        print("{}\t{}\t{}\t{}\t{}\t{}".format(song.id, song.name, song.artist,
                                              song.album, song.playlist,
                                              song.nid))
    print("")  # 好看
Beispiel #29
0
 def save_item(self, item):
     '''写数据库'''
     session = Session()
     try:
         session.add(Item(**item))
         session.commit()
     except Exception as e:
         logger.warning('页面 {} 的数据写入数据库出错,错误原因{}'.format(item['link'], e))
         session.rollback()
     session.close()
Beispiel #30
0
    def get(self):
        try:
            user_id = int(self.get_cookie('user_id'))
        except TypeError:
            self.redirect('/user/login')

        session = Session()
        q_user = session.query(User)
        user = q_user.filter_by(id=user_id).one()
        self.render('info.html', user=user)