Example #1
0
def training_set():
    try:
        ## titles = dao.find('topics', 'title')
        ## titles = [title.title() for title in titles]
        return render_template('training-set.html')
    except Exception as e:
        traceback(e)
Example #2
0
 def test_identifyPopUpWindomByTitle(self):
     #导入异常
     from selenium.common.exceptions import NoSuchWindowException,TimeoutException
     #导入期望场景
     from selenium.webdriver.support import expected_conditions as EC
     #导入BY类
     from selenium.webdriver.common.by import By
     from selenium.webdriver.support.ui import WebDriverWait
     import traceback
     import time
     url ='F:\gitstorehouse\selenium3.0\webdriverAPI接口\测试页面\使用title属性识别和操作新弹出的浏览器窗口.html'
     self.driver.get(url)
     WebDriverWait(self.driver,10,0.5).until(EC.element_to_be_clickable((By.LINK_TEXT,'搜索'))).click()
     #获取当去页面所有打开的句柄
     all_hamdles = self.driver.window_handles
     #打印当前浏览窗口个数
     print(self.driver.current_window_handle)
     print(len(all_hamdles))
     print(all_hamdles)
     if len(all_hamdles) >0:
         try:
             for windowHandle in all_hamdles:
                 #切换窗口
                 self.driver.switch_to.window(windowHandle)
                 WebDriverWait(self.driver,10,0.5).until(EC.title_is)
                 print(self.driver.title)
                 if self.driver.title == '搜狗®宠物天下 - 爱宠物,爱生活':
                     WebDriverWait(self.driver,10,0.5).until(lambda x:x.find_element_by_xpath('//*[@id="main"]/h1'))
         except NoSuchWindowException as e:
              print(traceback(e))
         except TimeoutException as e:
             print(traceback(e))
         self.driver.switch_to.window(all_hamdles[0])
         print(self.driver.title)
         self.assertEqual(self.driver.title,'你喜欢的水果')
Example #3
0
    def updateUserMobile(self, uid, pnum):
        m = mmysql()
        try:
            sql = 'SELECT pnum FROM z_user WHERE uid = %s;' % uid
            m.Q(sql) 
            rs = m.fetchone()
            if not rs:
                return 'uid 对应的用户不存在'

            # 只有免注册的手机号才允许修改,开头是'200', '20', '300', '30'
            mobile = str(rs['pnum'])
            if mobile[:3] != self._PREFIX_ANDROID_OLD and mobile[:2] != self._PREFIX_ANDROID_NEW and mobile[:3] != self._PREFIX_IOS_OLD and mobile[:2] != self._PREFIX_IOS_NEW:
                return '不允许修改手机号'

            # 检查手机号是否已经存在
            sql = 'SELECT * FROM z_user WHERE pnum = %s;' % pnum
            m.Q(sql)
            if m.fetchone():
                return '新手机号已经被其他账号绑定'

            # 可以更改了
            sql = 'UPDATE z_user SET pnum = %s, pnum_md5 = "%s", update_time = NOW() WHERE uid = %s;' % (pnum, self._get_pnum(pnum), uid)
            m.Q(sql)
            self.cacheUpdateUserInfo(uid)
            return ''
        except:
            traceback().print_exc()
        finally:
            m.close()
        
        return '服务器错误'
Example #4
0
def training_set():
    try:
        ## titles = dao.find('topics', 'title')
        ## titles = [title.title() for title in titles]
        return render_template('training-set.html')
    except Exception as e:
        traceback(e)
Example #5
0
    def updateUserMobileForAdmin(self, uid, old_mobile, new_mobile):
        m = mmysql()
        try:
            sql = 'SELECT pnum FROM z_user WHERE uid = %s AND pnum = %s;' % (uid, old_mobile)
            m.Q(sql) 
            rs = m.fetchone()
            if not rs:
                return 'uid 和 old_mobile 对应的用户不存在'

            # 检查新手机号是否已经存在
            sql = 'SELECT * FROM z_user WHERE pnum = %s;' % new_mobile
            m.Q(sql)
            if m.fetchone():
                return '新手机号已经被其他账号绑定'

            # 走到这里说明是 web 版的手机号,可以更改了
            sql = 'UPDATE z_user SET pnum = %s, pnum_md5 = "%s", update_time = NOW() WHERE uid = %s;' % (new_mobile, self._get_pnum(new_mobile), uid)
            m.Q(sql)
            self.cacheUpdateUserInfo(uid)
            return ''
        except:
            traceback().print_exc()
        finally:
            m.close()
        
        return '服务器错误'
        def run1(q, db_host, db_user, db_psw, db_port, db, sshHost, sshPort,
                 sshUser, sshPsw, sshKey):
            if not db_host or not db_user or not db_psw or not db_port or not db or not sshHost or not sshPort or not sshUser:
                globalVars.getLogger().error("参数错误")
                q.put(0)
                return
            if (not sshPsw and not sshKey):
                globalVars.getLogger().error("参数错误")
                q.put(0)
                return
            try:
                if not sshPsw:
                    accessory_dir = os.path.join(settings.STATIC_ROOT,
                                                 "sshKeys")
                    keyUrl = "%s/%s" % (accessory_dir, sshKey)
                    if not os.path.exists(keyUrl):
                        globalVars.getLogger().error(keyUrl + "路径不存在")
                        q.put(0)
                        return

                    with SSHTunnelForwarder(
                        (sshHost, sshPort),
                            ssh_pkey=keyUrl,
                            ssh_username=sshUser,
                            remote_bind_address=(db_host, db_port)) as server:
                        # print server
                        conn = MySQLdb.connect(
                            host='127.0.0.1',
                            port=server.local_bind_port,
                            user=db_user,
                            passwd=db_psw,
                            db=db,
                            charset="utf8",
                            cursorclass=MySQLdb.cursors.DictCursor)
                else:
                    with SSHTunnelForwarder(
                        (sshHost, sshPort),
                            ssh_password=sshPsw,
                            ssh_username=sshUser,
                            remote_bind_address=(db_host, db_port)) as server:
                        conn = MySQLdb.connect(
                            host='127.0.0.1',
                            port=server.local_bind_port,
                            user=db_user,
                            passwd=db_psw,
                            db=db,
                            charset="utf8",
                            cursorclass=MySQLdb.cursors.DictCursor)

            except Exception as e:
                globalVars.getLogger().error(
                    "连接数据库失败:" + CommonValueHandle.text2str(e.message))
                traceback()
                q.put(0)
                return
            else:
                globalVars.getLogger().error("连接数据库失败:")
                q.put(1)
                return
Example #7
0
 def dbcloseconnection(self):
     """
     Disconnect from host
     """
     try:
         if self.Client is not None:
             self.Client.close()
     except:
         traceback('Failed to disconnect the database')
Example #8
0
 def dbconnect(self):
     """
     Connect to the host.
     """
     try:
         if self.Client is None:
             self.Client = pymongo.MongoClient(self.host, self.port)
     except pymongo.errors.OperationFailure as err:
         traceback(err)
def about():
    try:
        if 'email' in session and 'first_name' in session:
            context = {'in_session': True, 'first_name': session['first_name']}
        else:
            context = {'in_session': False}
        return render_template('about.html', **context)
    except Exception as e:
        traceback(e)
Example #10
0
def unsubscribe():
    try:
        if 'email' in session:
            email = session['email']
            context = {'in_session': True, 'first_name': session['first_name']}
        else:
            context = {'in_session': False}
        return render_template('unsubscribe.html', **context)
    except Exception as e:
        traceback(e)
Example #11
0
def unsubscribe_successful():
    try:
        email_found = request.args.get('email_found')
        if email_found == "True":
            email_found = True
        elif email_found == "False":
            email_found = False
        session.clear()
        return render_template('/unsubscribe-successful.html', email_found = email_found)
    except Exception as e:
        traceback(e)
Example #12
0
def action(name, args):
    # TODO: proper action launching..
    try:
        import worldregistry
        action = worldregistry.world.actions[name]
    except KeyError:
        warning('unknown action called')
        traceback()
        return False
    else:
        return action.applyAction(args)
Example #13
0
 def dbconnectdatabase(self, dbname):
     """
     Establish connection to Database
     :params : dbname
     :type   : string
     """
     try:
         self.dbconnect()
         self.db = self.Client[dbname]
         self.dbcloseconnection()
     except pymongo.InvalidName as err:
         traceback(err)
Example #14
0
    def traceback(self):
        traceback(self)
        try:
            self.clear_headers()
            self.clear_output()
            self.set_header("Content-Type", "text/html; charset=iso-8859-1")
        except SequencingError:
            pass
        self.write("""\
<html><head><title>Error</title></head>
<body><h1>Error</h1>
<p>Sorry, an error occurred. Please try again later.</p>
</body></html>""")
Example #15
0
 def getcollectionlist(self, dbname):
     """
     :params : dbname
     :type   : string
     """
     try:
         self.CollectionList = []
         self.dbconnect()
         self.db = self.Client[dbname]
         self.CollectionList = self.db.collection_names(include_system_collections = False)
         self.dbcloseconnection()
     except TypeError as err:
         traceback(err)
Example #16
0
 def isTestUser(self, pnum):
     m = mmysql()
     try:
         sql = 'SELECT who FROM test_user_list WHERE pnum = %s;' % pnum
         m.Q(sql)
         rs = m.fetchone()
         if rs:
             return True
     except:
         traceback().print_exc()
     finally:
         m.close()
     
     return False
Example #17
0
 def dbgetcollection(self, dbname, collection):
     """
     Check Collections and connect
     :params : dbname
     :type   : string
     :param  : collection
     :type   : string
     """
     try:
         self.dbconnect()
         self.db = self.Client[dbname]
         self.collection = self.db[collection]
         self.dbcloseconnection()
     except pymongo.InvalidName as err:
         traceback(err)
Example #18
0
    def run(self):
        time.sleep(.1)
        self.resume()  # unpause self
        while True:
            with self.state:
                if self.paused:
                    self.state.wait()  # block until notified
            self.CurThread = int(self.getName().replace('Thread-', '')) - 1

            self.Account = Manager.GetAccount()
            username, password = self.Account.split(':')
            Lprint('Thread-{0} using account {1}'.format(
                self.CurThread, username))
            try:
                MakeConf(self.CurThread, username, password)
                StartCmd = "python pokecli.py -af configs/temp/auth-{0}.json -cf configs/temp/config-{0}.json --walker_limit_output {1}".format(
                    self.CurThread, MultiBotConfig[u'walker_limit_output'])
                if MultiBotConfig[u'UseProxy']:
                    proxy2 = Manager.getProxy()
                    if platform.system() == "Linux":
                        # os.system('export HTTP_PROXY="http://' + proxy + '"; export HTTPS_PROXY="https://' + proxy + '"; ' + StartCmd)
                        pass
                    if platform.system() == "Windows":
                        pass
                        # os.system('set HTTP_PROXY="http://' + proxy + '" & set HTTPS_PROXY="https://' + proxy + '" & ' + StartCmd)
                else:
                    pass
                    # os.system(StartCmd)
            except Exception as e:
                Lprint((traceback()))
                time.sleep(60)
            except KeyboardInterrupt:
                stop()
            finally:
                self.Manager.SetAccount(self.Account)
Example #19
0
 def test_HandleFrame(self):
     from selenium.webdriver.support import expected_conditions as EC
     from selenium.webdriver.support.ui import WebDriverWait
     from selenium.common.exceptions import TimeoutException
     from selenium.webdriver.common.by import By
     import traceback
     import time
     url='F:\gitstorehouse\selenium3.0\webdriverAPI接口\测试页面\\frameset.html'
     self.driver.get(url)
     #使用索引的方式进入frame
     time.sleep(5)
     self.driver.switch_to.frame(0)
     leftframetext = self.driver.find_element_by_xpath('/html/body/p')
     self.assertEqual(leftframetext.text,'这是左侧frame 页面的信息')
     self.driver.find_element(By.XPATH,'/html/body/input').click()
     try:
         alertwindow = WebDriverWait(self.driver,10,1).until(EC.alert_is_present())
         print(alertwindow.text)
         alertwindow.accept()
     except TimeoutException as e:
         print(traceback(e))
     self.driver.switch_to.default_content()
     #通过页面标签对象定位
     self.driver.switch_to.frame(self.driver.find_elements(By.TAG_NAME,'frame')[1])
     assert  '这是中间frame' in self.driver.page_source
     self.driver.find_element(By.TAG_NAME,'input').send_keys('中间')
     #返回最外层
     self.driver.switch_to.default_content()
     # 通过页面标签对象定位
     self.driver.switch_to.frame(self.driver.find_element(By.ID,'rightframe'))
     assert '这是右侧frame页面上的文字' in self.driver.page_source
     self.driver.switch_to.default_content()
Example #20
0
 async def get_screenshot(self, retry=3):
     browser = await launch(args=['--no-sandbox'])
     page = await browser.newPage()
     for i in range(retry + 1):
         try:
             await page.goto(self.url, waitUntil="networkidle0", timeout=10000)
             await page.setViewport(viewport={'width': 2560, 'height': 1080})
             card = await page.querySelector(".card")
             clip = await card.boundingBox()
             bar = await page.querySelector(".text-bar")
             bar_bound = await bar.boundingBox()
             clip['height'] = bar_bound['y'] - clip['y']
             self.img = "base64://" +\
                 await page.screenshot(clip=clip, encoding='base64')
             break
         except TimeoutError as e:
             logger.error(f"截图失败(连接超时) 已重试({i}/{retry})")
         except BadStatusLine as e:
             logger.error(f"截图失败(连接错误) 已重试({i}/{retry})")
         except Exception as e:
             logger.error("截图失败(未知错误),以下为错误日志")
             logger.error(traceback(e))
             await browser.close()
             raise
         finally:
             if i == retry:
                 try:
                     getattr(self, 'img')
                 except AttributeError:
                     logger.error("已达到重试上限,将在下个轮询中重新尝试")
                     await browser.close()
                     raise
         await asyncio.sleep(0.1)
     await browser.close()
Example #21
0
def matchTraceback(file, lineNumber, routine):
    tracebackText = traceback()
    lineFlag = "line %d" % lineNumber
    for line in tracebackText.splitlines():
        if file in line and lineFlag in line and routine in line:
            return True
    return False
Example #22
0
def remove_email():
    try:
        email_list = data_access.select_records("email", None)
        if request.method == "POST":
            email = request.form['email']
        else:
            if 'email' in session:
                email = session['email']
        if email in email_list:
            data_access.delete_record("email", email)
            context = {'email_found': True}
        else:
            context = {'email_found': False}
        return redirect(url_for('unsubscribe_successful', **context))
    except Exception as e:
        traceback(e)
Example #23
0
def index():
    try:
        forced = request.args.get('forced')
        if forced is not None:
            forced = True
        valid_email = request.args.get('valid_email')
        if valid_email is not None:
            valid_email = False
        else:
            valid_email = True
        if 'email' in session and not forced:
            return redirect(url_for('about'))
        else:
            return render_template('index.html', valid_email = valid_email)
    except Exception as e:
        traceback(e)
Example #24
0
def thank_you():
    try:
        prev_exist = request.args.get('prev_exist')
        if prev_exist is not None:
            prev_exist = str_to_bool(prev_exist)
        if prev_exist:
            if 'first_name' in session:
                context = {'prev_exist': True, 'first_name': session['first_name']}
            else:
                context = {'prev_exist': True}
        else:
            if 'first_name' in session:
                context = {'prev_exist': False, 'first_name': session['first_name']}
            else:
                context = {'prev_exist': False}
        return render_template('thank-you.html', **context)
    except Exception as e:
        traceback(e)
Example #25
0
def signup():
    try:
        first_name, last_name, email = request.form['first-name'], request.form['last-name'], request.form['email']
        email_list = data_access.select_records("email", None)
        if not validate_email(email):
            return redirect(url_for('index', valid_email = False))
        if email not in email_list:
            data = {'first_name': first_name, 'last_name': last_name, 'email': email}
            data_access.insert_record(**data)
            session['first_name'], session['last_name'], session['email'] = first_name, last_name, email
            try:
                signup_confirmation(session['first_name'])
            except Exception as e:
                traceback(e)
            prev_exist = False
        else:
            prev_exist = True
        return redirect(url_for('thank_you', prev_exist = prev_exist))
    except Exception as e:
        traceback(e)
Example #26
0
async def dy_sched():
    """直播推送"""

    async with DB() as db:
        uid = await db.next_uid('dynamic')
        if not uid:
            return
        user = await db.get_user(uid)
        assert user is not None
        name = user.name

    logger.debug(f'爬取动态 {name}({uid})')
    br = BiliReq()
    dynamics = (await br.get_user_dynamics(uid)).get('cards', [])  # 获取最近十二条动态
    # config['uid'][uid]['name'] = dynamics[0]['desc']['user_profile']['info']['uname']
    # await update_config(config)

    if len(dynamics) == 0:  # 没有发过动态或者动态全删的直接结束
        return

    if uid not in last_time:  # 没有爬取过这位主播就把最新一条动态时间为 last_time
        dynamic = Dynamic(dynamics[0])
        last_time[uid] = dynamic.time
        return

    for dynamic in dynamics[4::-1]:  # 从旧到新取最近5条动态
        dynamic = Dynamic(dynamic)
        if dynamic.time > last_time[uid] and dynamic.time > datetime.now(
        ).timestamp() - timedelta(minutes=10).seconds:
            logger.info(f"检测到新动态({dynamic.id}):{name}({uid})")
            image = None
            for _ in range(3):
                try:
                    image = await get_dynamic_screenshot(dynamic.url)
                    break
                except Exception as e:
                    logger.error("截图失败,以下为错误日志:")
                    logger.error(traceback(e))
                await asyncio.sleep(0.1)
            if not image:
                logger.error("已达到重试上限,将在下个轮询中重新尝试")
            await dynamic.format(image)

            async with DB() as db:
                push_list = await db.get_push_list(uid, 'dynamic')
                for sets in push_list:
                    await safe_send(sets.bot_id, sets.type, sets.type_id,
                                    dynamic.message)

            last_time[uid] = dynamic.time
    await DB.update_user(uid, dynamic.name)  # type: ignore
Example #27
0
def get_youtube_video_info(id):
    import requests, urllib.parse
    VALID_VIDEO_INFO_KEYS = ['title', 'length_seconds', 'iurl']
    try:
        url = 'https://www.youtube.com/get_video_info?html5=1&video_id=%s' % id
        resp = requests.get(url)
        if resp and resp.status_code == 200:
            if 'errorcode' in resp.text:
                print('get video info failed, response: %s', resp.text)
                return None
            kvs = [kv.split('=') for kv in resp.text.split('&')]
            filtered_kvs = list(
                filter(lambda kv: kv[0] in VALID_VIDEO_INFO_KEYS, kvs))
            filtered_kvs.append(['youtube_id', id])
            return dict(
                map(lambda kv: (kv[0], urllib.parse.unquote(kv[1])),
                    filtered_kvs))
        else:
            print('invalid response: %s', resp)
    except Exception as e:
        traceback()
    print('get youtube video info failed, id: %s' % id)
    return None
    def POST(self):
        try:
            web_data = web.data()
            mylog.logger.info("Handle Post webdata is %s" % web_data)  # 后台打日志
            web_data_u = web_data.decode('utf-8')
            encode = json.loads(web_data_u)
            mylog.logger.info(web_data_u)
            preprocess_stat = 0
            if "MsgHead" in encode.keys():
                head_validate = msg_processor.verify_msg(encode)
                if head_validate == 0:
                    msg_processor.add_task_queue(encode)
                preprocess_stat = head_validate
            else:
                preprocess_stat = 1
            cmdwd = encode["MsgHead"]["Cmd"]
            response_msg = msg_processor.gen_resp(encode["MsgHead"]["MsgID"],
                                                  cmdwd, preprocess_stat)
            mylog.logger.info(response_msg)
            return response_msg

        except Exception as Argment:
            traceback()
            return Argment
Example #29
0
File: py.py Project: QGB/QPSU
def traceback(ae=None):
	import traceback
	if not ae:return traceback.print_last()
	if is3():
		tb=getattr(ae,'__traceback__',0)
		if not tb:return traceback()
		return traceback.print_tb(tb)
	if is2():
		print('NotImplementedError')
		return
	try:
		a,e,tb=sys.exc_info()
		traceback.print_tb(tb)

	except Exception as e:
		print(e)
		return e
Example #30
0
def find_path (source_point, destination_point, mesh) :
	path = []
	visited = []
			
	#Dictionary declarations:
	prev = {}
	dist = {}
	
	#set dist and prev for src
	dist[find_box(source_point, mesh)] = 0
	prev[find_box(source_point, mesh)] = None
	
	#q is list of unvisited boxes
	q = []
	
	source_box = find_box(source_point, mesh);
	
	#push source_point onto q
	heappush(q, (0, source_box))
	
	destination_box = find_box(destination_point , mesh);
	inDist = 0
	altDist = 0
	#Iterate through q
	while q:
		#Store the cell and goal
		_,cell = heappop(q)
		
		#Get all the neighbors of that box
		neighbors = mesh['adj'][cell]		
		#If destination, return
		if cell == destination_box:
			return (traceback(prev,cell,source_point, destination_point), visited)
		for n in neighbors:
			visited.append(n)
			#alt is the distance from source to this neighbor, with the heuristic too
			alt = dist[cell] + distance(cell,n)
			#If this is shorter than the previous shortest
			if n not in dist or alt < dist[n]:
				dist[n] = alt
				prev[n] = cell
				heappush(q,((alt+distance(n,destination_box)),n))
	print "No path possible"
	return path, visited
Example #31
0
    else: 
        parser = chem.parse.getParser(file)


    computation = None
    if parser:
        computation = parser.getComputation(weakFind)
    else:
        #oops, must be an input file
        try:
            computation = chem.input.readInputFile(file, reorient=reorient, recenter=recenter)
        except Exception, error:
            import globalvals
            if globalvals.Debug.debug:
                print error
                print traceback(error)

    if computation:
        for key in kwargs:
            computation.setAttribute(key, kwargs[key])

    return computation

def getComputationInFolder(folder = ".", globstring = "*"):
    currentDir = os.getcwd()
    os.chdir(folder) 
    import glob
    file_list = glob.glob(globstring)
    for file in file_list:
        comp = getComputation(file)
        if comp:   
Example #32
0
def get_embedding_as_df(logger=None,
                        verbose=False,
                        df_input=None,
                        column_to_computing=None,
                        columns_to_save=[],
                        root_name_vect_cols='dim_',
                        dim_embeddings=768,
                        path_embeddings_model=None,
                        type_model='BERT',
                        python_pkg='bert-embeddings',
                        file_save_pickle=None,
                        file_save_gz=None,
                        sep_out='|'):

    try:
        if column_to_computing is not None and df_input is not None:

            lst_embeddings = []

            ####
            #### ...get embeddings for each word in a phrase as dataframe
            if type_model == 'BERT':
                if python_pkg == 'bert-embeddings':
                    #### ...iteration on each cell in the selected column to process...s
                    for iter in df_input.index:
                        df_embeddings = get_bert_embedding_of_several_words_as_pd_df(
                            logger=logger,
                            phrase_in=df_input[column_to_computing][iter],
                            root_colnames=root_name_vect_cols,
                            dim_vector_rep=dim_embeddings)

                        #### ...insert columns to save in output...
                        #### we iter on inversed list to conserve the order of fields introduced
                        for c in reversed(columns_to_save):
                            df_embeddings.insert(0, c, [
                                df_input[c][iter]
                                for i in range(len(df_embeddings))
                            ])

                        if logger is not None and verbose == True:
                            logger.info(df_embeddings)

                        lst_embeddings.append(df_embeddings)

                        #### ...to clean the flow and memory treatment...
                        del df_embeddings

                    df_rep = pd.concat(lst_embeddings)

            if type_model == 'W2V':
                if python_pkg == 'gensim':
                    model = gensim.models.KeyedVectors.load_word2vec_format(
                        path_embeddings_model, binary=True)
                    for iter in df_input.index:
                        df_embeddings = get_w2v_embedding_of_several_words_as_pd_df(
                            logger=logger,
                            phrase_in=df_input[column_to_computing][iter],
                            root_colnames=root_name_vect_cols,
                            dim_vector_rep=dim_embeddings,
                            embeddings_model=model)

                        #### ...insert columns to save in output...
                        #### we iter on inversed list to conserve the order of fields introduced
                        for c in reversed(columns_to_save):
                            df_embeddings.insert(0, c, [
                                df_input[c][iter]
                                for i in range(len(df_embeddings))
                            ])

                        if logger is not None and verbose == True:
                            logger.info(df_embeddings)

                        lst_embeddings.append(df_embeddings)

                        #### ...to clean the flow and memory treatment...
                        del df_embeddings

                    df_rep = pd.concat(lst_embeddings)

                    #df_rep = pd.DataFrame()
                    print(df_rep)

            #### ...saving results as file...
            if file_save_pickle is not None:
                df_rep.to_pickle(file_save_pickle)
                if logger is not None:
                    logger.info(" - data saved in file pickle {0}".format(
                        file_save_pickle))
            if file_save_gz is not None:
                df_rep.to_csv(file_save_gz,
                              sep=sep_out,
                              header=True,
                              index=False,
                              compression='gzip')
                if logger is not None:
                    logger.info(
                        " - data saved in gz file {0}".format(file_save_gz))

        else:
            traceback()
            raise Exception

    except Exception:
        if logger is not None:
            logger.exception("ERROR computing embeddings")
        raise Exception

    return df_rep
Example #33
0
def enterprise_upload():
    username = session.get("username", "")
    password = session.get("password", "")
    enterprise, signer = login(username, password)

    if enterprise is None:
        return redirect("/enterprise")

    if request.method == "GET":
        return render_template("enterprise2-1.html",
                               is_login=True,
                               enterprise=enterprise,
                               username=username)

    data_hash = request.form.get("data-hash")
    data_file = request.files.get("data-file")

    if data_file is None:
        return render_template("enterprise2-1.html",
                               is_login=True,
                               enterprise=enterprise,
                               username=username,
                               fail_msg="缺少上传文件")
    if data_file.filename == "":
        return render_template("enterprise2-1.html",
                               is_login=True,
                               enterprise=enterprise,
                               username=username,
                               fail_msg="缺少上传文件")

    data_file_path = os.path.join(app.config["UPLOAD_FOLDER"],
                                  secure_filename(data_file.filename))
    data_file.save(data_file_path)

    try:
        _, _, n, _ = count_numbers()
        t = 3
        key, shares = shamir_encode(t, n)

        enc_data_path = os.path.join(
            app.config["UPLOAD_FOLDER"],
            "enc-" + secure_filename(data_file.filename))
        aes_encode(key, data_file_path, enc_data_path)

        data_file_addr = ipfs_client.add(enc_data_path)

        for i, audit in enumerate(Audit.query.all()):
            obj_data = IPFSObject(hash=data_file_addr["Hash"],
                                  name=secure_filename(data_file.filename),
                                  secret=shares[i][1].hex(),
                                  idx=shares[i][0])
            audit.files.append(obj_data)
            db.session.add(obj_data)
            db.session.commit()
    except Exception as e:
        traceback(e)
        return render_template("enterprise2-1.html",
                               is_login=True,
                               enterprise=enterprise,
                               username=username,
                               succ_msg="IPFS上传失败")

    try:
        call_contract(enterprise.contract_addr,
                      "Enterprise",
                      "updateData",
                      args=[data_hash, data_file_addr["Hash"]],
                      signer=signer)
    except Exception as e:
        traceback(e)
        return render_template("enterprise2-1.html",
                               is_login=True,
                               enterprise=enterprise,
                               username=username,
                               succ_msg="智能合约调用失败")
    return render_template("enterprise2-1.html",
                           is_login=True,
                           enterprise=enterprise,
                           username=username,
                           succ_msg="添加成功")
Example #34
0
def add_directors():
    with open(director_file, 'rt', encoding='utf8') as f:
        reader = csv.reader(f)
        director_list = list(reader)

    http = urllib3.PoolManager()

    for director in director_list:

        director_name = director[2].strip()
        director_company = director[1].strip()
        director_ticker = director[0].strip()
        director_title = director[3].strip()

        if director[4].strip() == 0:
            director_independent = False
        else:
            director_independent = True

        if director[5].strip() == "":
            if debug:
                print("No age found, blanking")
            director_age = ""
        else:
            director_age = str(director[5].strip())

        director_startdate = director[6].strip() + "-01-01"
        director_id = None

        # Check if director exists
        try:
            # This logic assumes that there is only one director with the same name and the same age
            url = requote_uri(directors_url + "?format=json&name=" + director_name + "&age=" + director_age)
            r = http.request('GET', url)

            jsondata = json.loads(r.data.decode('utf-8'))

            if len(jsondata) == 0:
                print("Adding director: " + director_name + " (" + director_age + ")")

                # Create json payload
                payload = {
                    'name': director[2].strip(),
                    'age': director_age
                }

                # Add Director
                r = http.urlopen('POST', directors_url, headers=header, body=json.dumps(payload))

                # Get Director ID
                jsondata = json.loads(r.data.decode('utf-8'))
                director_id = str(jsondata['id'])

            else:
                print("Found director: " + director_name + " - " + director_age)
                # Get Director ID
                director_id = str(jsondata[0]['id'])

        except Exception as e:
            print("Somthing bad happened")
            traceback(e)

        # Search for director on company board
        if director_id is None:
            print("Could not find director_id")
            break

        try:
            # Get Company ID
            url = requote_uri(companies_url + "?format=json&name=" + director_company)
            jsondata = getJSONData(url)

            # Found the company
            if len(jsondata) != 0:
                company_id = str(jsondata[0]['id'])
                print("Found ID: " + company_id + " for company " + director_company)
            else:
                print("ERROR: Company not found!")
                continue

            url = requote_uri(boards_url + "?format=json&company=" + company_id + "&director=" + director_id)
            jsondata = getJSONData(url)

            if len(jsondata) == 0:
                # Director is not on the board
                payload = {
                    'company': company_id,
                    'director': director_id,
                    'start_date': director_startdate,
                    'is_current': "True",
                    'is_independent': director_independent,
                    'title': director_title
                }
                r = http.urlopen('POST', boards_url, headers=header, body=json.dumps(payload))

                if r.status == 201:
                    print("Added director " + director_name + " to company " + director_company)
                else:
                    print("An error ocurred added boardmember")


        except Exception as e:
            print(str(e))
Example #35
0
def index():
    try:
        return render_template('index.html')
    except Exception as e:
        traceback(e)
Example #36
0
 def traceback(self, req):
     """Display a traceback, req is a Request object."""
     traceback(req, html=1)
Example #37
0
def quote():
    try:
        return render_template('quote.html')
    except Exception as e:
        traceback(e)
Example #38
0
def trans_config(filename, cv=None, done_list=None, config_type=1):
    """通过对应的数据表 生成相应的配置"""
    rs = []

    xl = openpyxl.load_workbook(
        filename=filename)  # 仅支持xlsx   use_iterators=True
    import game_config
    config_name_list_raw = game_config.config_name_list
    config_name_list = zip([i[0] for i in config_name_list_raw if i[3]],
                           [i[4] for i in config_name_list_raw if i[3]])

    done_list = done_list or []
    cv = cv or ConfigVersionManager.get_config_version_obj(
        config_type=config_type)
    need_private_city_test = False
    for sheet in xl.worksheets:
        config_name = ''
        sheet_title = sheet.title.strip()
        if 'map' in sheet_title or 'title_detail' in sheet_title:
            need_private_city_test = True

        # 特殊处理
        tt = sheet_title.split('_')
        if len(tt) == 2 and tt[1].isdigit():
            if tt[0] == 'map':
                upload_map_status = upload_map(tt[1],
                                               sheet,
                                               config_type=config_type)
                if upload_map_status:
                    cv.update_single('map', hex_version=upload_map_status)
                continue
            elif tt[0] == 'middle':
                upload_middle_map_data_status = upload_middle_map_data(
                    tt[1], sheet, config_type=config_type)
                if upload_middle_map_data_status:
                    cv.update_single('middle_map_data',
                                     hex_version=upload_middle_map_data_status)
                    done_list.append(sheet_title)
                continue

        # 处理box_reward_
        if len(tt) == 3 and '%s_%s' % (tt[0], tt[1]) == 'box_reward':
            upload_box_reward_status = upload_box_reward(
                int(tt[2]), sheet, config_type=config_type)
            if upload_box_reward_status:
                cv.update_single('box_reward_new',
                                 hex_version=upload_box_reward_status)
                done_list.append(sheet_title)
            continue

        # 特殊处理
        for i in config_name_list:
            if sheet_title in i:
                config_name = i[0]
        if not config_name:
            continue

        if config_name == 'guide':
            upload_guide_status = upload_guide(config_name,
                                               sheet,
                                               config_type=config_type)
            if upload_guide_status:
                cv.update_single(config_name, hex_version=upload_guide_status)
                done_list.append(sheet_title)
            continue

        data = xls_convert.to_pyobj(sheet)
        # 针对在config_templates里指明的label进行内容逻辑测试
        # 含'guide', 'middle', 'map', 'box_reward'的表在获得本函数使用的data前,已进行预处理。
        # 如要对上述表进行检测,需阅读预处理代码,避免潜在冲突
        has_bug = content_logic_check(config_name, sheet_title, data)
        if has_bug:
            return has_bug, 'bug', need_private_city_test

        try:
            str_config = xls_convert.to_config_string(config_name, data)
        except Exception, e:
            etype, value, tb = sys.exc_info()
            line = traceback.format_exception_only(etype, value)
            raise KeyError("table=", sheet_title, line)

        try:
            d = eval(str_config)
        except Exception, e:
            file_dir = os.path.join(_settings.BASE_ROOT, 'logs')
            if not os.path.exists(file_dir):
                os.makedirs(file_dir)
            error_file = os.path.join(file_dir, 'config_error.py')
            with open(error_file, 'w') as f:
                f.write('# encoding: utf-8 \n')
                f.write('# config_name: %s \n' % config_name)
                f.write(str_config.encode('utf-8'))
            traceback()
            raise e
Example #39
0
def index():
    try:
        return render_template('index.html')
    except Exception as e:
        traceback(e)
Example #40
0
def quote():
    try:
        return render_template('quote.html')
    except Exception as e:
        traceback(e)
Example #41
0
        #try map(game**py, augment['character', 'secret', ...] -> list
    else:
        area.append(StandardError)
        area.__delslice__(-1, 1)  # <==> delattr
        help(SecurityError(AutoGenerate(Matrix.__compound__)))
        if (omega == alpha):
            print
            """
				For a list of help instructions, please press one of the following keys:
				-h			- Prints a list of helpful instructions
				-l			- Returns a Non Null value -1,1 determining coordinates
				-a			- Return to Sender
				-k			- Send to Returner
			"""
        else:
            traceback(omega, alpha)
            execfile(Cerberus[reversed, Amethyst[reduce, set]])
            """
				has_secure_password
				password_digest = "root/toor"
				add_executive_func_call(SystemExit)
				update_priority_queue(SystemStackError(Thamos))
				update_stack_in_func_call(GenerateAutoDefinition[Zakros_])
				pause_instalation.(__FILE__).inline.stream(execute(execution[uniq_id.rb]))
				update_intrusion_detection = true
				trust(inline.stream.file.io/object_id)
			"""
            coerce(a, b, c), repr(omega)
            logging.addLevelName(alpha, "Omega")
            long(x[64])
            __name__.alpha == false
        def run1(q, db_host, db_user, db_psw, db_port, db, sshHost, sshPort,
                 sshUser, sshPsw, sshKey, sql, sqlAssert):
            def runSql(conn, sql):
                if not sql:
                    return 1
                if not conn:
                    return 0
                try:
                    cursor = conn.cursor()
                    cursor.execute(sql)
                    conn.commit()
                    data = cursor.fetchall()
                    print(data)
                except Exception as e:
                    conn.rollback()
                    globalVars.getLogger().error(
                        "执行sql失败:" + CommonValueHandle.text2str(e.message))
                    return 0
                else:
                    cursor.close()
                    conn.close()
                    return 1

            def runSqlAssert(conn, sql, sqlAssert):
                if not sql or not sqlAssert or not conn:
                    return 1
                # 使用cursor()方法获取操作游标
                cursor = conn.cursor()
                ret = True
                try:
                    cursor.execute(sql)
                    # 获取所有记录列表
                    results = cursor.fetchall()
                    nums = len(results)
                    try:
                        if re.search(r'^=\d+$', sqlAssert):
                            ass = int(sqlAssert[1:])
                            ret = (ass == nums)
                        elif re.search(r'^!=\d+$', sqlAssert):
                            ass = int(sqlAssert[2:])
                            ret = (ass != nums)
                        elif re.search(r'^>=\d+$', sqlAssert):
                            ass = int(sqlAssert[2:])
                            ret = (ass >= nums)
                        elif re.search(r'^<=\d+$', sqlAssert):
                            ass = int(sqlAssert[2:])
                            ret = (ass <= nums)
                        elif re.search(r'^>\d+$', sqlAssert):
                            ass = int(sqlAssert[1:])
                            ret = (ass > nums)
                        elif re.search(r'^<\d+$', sqlAssert):
                            ass = int(sqlAssert[1:])
                            ret = (ass < nums)
                        else:
                            ret = False
                    except Exception as e:
                        globalVars.getLogger().error(e.message)
                        ret = False
                except Exception as e:
                    globalVars.getLogger().error(
                        "执行sql失败:" + CommonValueHandle.text2str(e.message))
                    ret = False
                else:
                    cursor.close()
                    conn.close()
                if ret:
                    return 1
                else:
                    return 0

            if not sql:
                q.put(1)
                return

            if not db_host or not db_user or not db_psw or not db_port or not db or not sshHost or not sshPort or not sshUser:
                q.put(0)
                return

            if (not sshPsw and not sshKey):
                q.put(0)
                return

            try:
                if not sshPsw:
                    accessory_dir = os.path.join(settings.STATIC_ROOT,
                                                 "sshKeys")
                    keyUrl = "%s/%s" % (accessory_dir, sshKey)
                    if not os.path.exists(keyUrl):
                        q.put(0)
                        return

                    with SSHTunnelForwarder(
                        (sshHost, int(sshPort)),
                            ssh_pkey=keyUrl,
                            ssh_username=sshUser,
                            remote_bind_address=(db_host,
                                                 int(db_port))) as server:
                        conn = MySQLdb.connect(
                            host='127.0.0.1',
                            port=server.local_bind_port,
                            user=db_user,
                            passwd=db_psw,
                            db=db,
                            charset="utf8",
                            cursorclass=MySQLdb.cursors.DictCursor)
                        if "None" == sqlAssert:
                            q.put(runSql(conn, sql))
                        else:
                            q.put(runSqlAssert(conn, sql, sqlAssert))
                        return
                else:
                    with SSHTunnelForwarder(
                        (sshHost, int(sshPort)),
                            ssh_password=sshPsw,
                            ssh_username=sshUser,
                            remote_bind_address=(db_host,
                                                 int(db_port))) as server:
                        conn = MySQLdb.connect(
                            host='127.0.0.1',
                            port=server.local_bind_port,
                            user=db_user,
                            passwd=db_psw,
                            db=db,
                            charset="utf8",
                            cursorclass=MySQLdb.cursors.DictCursor)

                        if "None" == sqlAssert:
                            q.put(runSql(conn, sql))
                        else:
                            q.put(runSqlAssert(conn, sql, sqlAssert))
                        return
            except Exception as e:
                traceback()
                globalVars.getLogger().error(
                    "连接数据库失败:" + CommonValueHandle.text2str(e.message))
                q.put(0)
                return
Example #43
0
def upload():
    username = session.get("username", "")
    password = session.get("password", "")
    agency, signer = login(username, password)

    if agency is None:
        return redirect("/agency")
    
    if request.method == "GET":
        return render_template("agency2-2.html", is_login = True, agency = agency, username = username)

    ent_name = request.form.get("ent-name")
    eng_list = request.form.get("eng-list", "")
    eng_list = [e for e in eng_list.split()]
    data_hash = request.form.get("data-hash")
    if ent_name is None:
        return render_template("agency2-2.html", is_login = True, agency = agency, username = username, fail_msg = "缺少生产企业名称")

    _,_,aal,_ = count_numbers()
    if aal < 3:
        return render_template("agency2-2.html", is_login = True, agency = agency, username = username, fail_msg = "缺少足够的审查实体,至少需要3家审查实体")

    enterprise = Enterprise.query.filter(Enterprise.username == ent_name).first()
    if enterprise is None:
        return render_template("agency2-2.html", is_login = True, agency = agency, username = username, fail_msg = "生产企业名称错误")
    
    data_file = request.files.get("data-file")

    if data_file is None:
        return render_template("agency2-2.html", is_login = True, agency = agency, username = username, fail_msg = "缺少上传文件")
    if data_file.filename == "" : 
        return render_template("agency2-2.html", is_login = True, agency = agency, username = username, fail_msg = "缺少上传文件")

    data_file_path = os.path.join(app.config["UPLOAD_FOLDER"], secure_filename(data_file.filename))
    data_file.save(data_file_path)

    try:
        n = aal
        t = 3
        key, shares = shamir_encode(t, n)

        enc_data_path = os.path.join(app.config["UPLOAD_FOLDER"], "enc-"+secure_filename(data_file.filename))
        aes_encode(key, data_file_path, enc_data_path)

        data_file_addr = ipfs_client.add(enc_data_path)

        for i, audit in enumerate(Audit.query.all()):

            obj_data = IPFSObject(hash = data_file_addr["Hash"], name = secure_filename(data_file.filename), secret = shares[i][1].hex(), idx = shares[i][0])
            audit.files.append(obj_data)
            db.session.add(obj_data)
            db.session.commit()
    except Exception as e:
        traceback(e)
        return render_template("agency2-2.html", is_login = True, agency = agency, username = username, succ_msg = "IPFS上传失败")

    try:
        res = call_contract(enterprise.contract_addr, "Enterprise", "update", args=[data_hash, data_file_addr["Hash"], to_checksum_address(agency.contract_addr), eng_list], signer = signer)
        enterprise.evaluation_addr = res[0]
        db.session.commit()

        res = call_contract(enterprise.evaluation_addr, "ReportEvaluation", "businessUpdate", args = [] , signer = signer)
        licenseAddr = res[0]
        enterprise.license_addr = licenseAddr
        db.session.commit()
    except Exception:
        traceback.print_exc()
        return render_template("agency2-2.html", is_login = True, agency = agency, username = username, succ_msg = "智能合约调用失败")
    return render_template("agency2-2.html", is_login = True, agency = agency, username = username, succ_msg = "添加成功")
Example #44
0
    def func_main(self, gui_app):
        try:
            if 'win' in gui_app.guestOS():
                user_home = gui_app.winshell.folder("profile")
                desktop_path = os.path.join(gui_app.winshell.desktop(),
                                            'SimCav.lnk')
                startmenu_path = os.path.join(gui_app.winshell.start_menu(),
                                              'Programs', 'SimCav.lnk')
            else:
                user_home = os.path.expanduser('~')
                desktop_path = os.path.join(user_home, 'Desktop',
                                            'SimCav.desktop')
                startmenu_path = os.path.join(user_home, '.local', 'share',
                                              'applications', 'SimCav.desktop')
            simcav_home = os.path.join(user_home, 'SimCav')

            # Removing SimCav folder
            gui_app.printcmd(
                "This will completely remove SimCav, including 'Saves' folder."
            )
            gui_app.printcmd("Path to delete: " + simcav_home)
            user_asnwer = gui_app.askuserbox('Continue?')

            if not user_asnwer:
                raise misc.UserCancel

            import shutil
            gui_app.printcmd('Deleting files...')
            for i in os.listdir(simcav_home):
                todelete = os.path.join(simcav_home, i)
                if os.path.isfile(todelete):
                    gui_app.printcmd('    Removing ' + i)
                    gui_app.printcmd(os.path.realpath(todelete))
                    os.remove(todelete)
                elif os.path.isdir(todelete):
                    gui_app.printcmd("    Removing folder '" + i + "'")
                    gui_app.printcmd(os.path.realpath(todelete))
                    shutil.rmtree(todelete)
            # Can't delete main folder while using it!
            #shutil.rmtree(simcav_home)

            # Removing shortcuts
            gui_app.printcmd('Deleting shortcuts')
            gui_app.printcmd('Removing ' + desktop_path)
            os.remove(desktop_path)
            gui_app.printcmd('Removing ' + startmenu_path)
            os.remove(startmenu_path)

            gui_app.printcmd('\nUninstall finished!')

        except Exception as inst:
            gui_app.printcmd('\nError: ' + type(inst).__name__)
            if type(inst).__name__ in [
                    'PythonVersionError', 'NotModuleError', 'PipInstallError',
                    'UserCancel'
            ]:
                gui_app.printcmd(inst.message)
            else:
                gui_app.printcmd(inst)
                import traceback
                gui_app.printcmd(traceback(inst))

        finally:
            gui_app.printcmd('You may close this window.')