예제 #1
0
    def decodeSubtitles(self, id, iv, data):
        compressed = True
        key = self.generateKey(id)
        iv = Common().ByteArrayToString(Base64Decoder().decode(iv))
        data = Common().ByteArrayToString(Base64Decoder().decode(data))
        data = iv + data
        cipher = AES_CBC(key, padding=noPadding(), keySize=32)
        decryptedData = cipher.decrypt(data)

        if compressed:
            return zlib.decompress(decryptedData)
        else:
            return decryptedData
예제 #2
0
파일: User.py 프로젝트: yangyang0910/Python
 def Login(self):
     username = input("用户名(或注册y or n)>>>:").strip()
     pawd = ""
     if username == "y" or username == "Y":
         self.setRegister()
         self.Login()
     else:
         pawd = input("password>>>:").strip()
     with open(self.__DB_User, "rb") as f:
         if os.path.getsize(self.__DB_User) == 0:
             read = {}
         else:
             read = pickle.loads(f.read())
     if username in read:
         if Common().Jem_hash(pawd, read[username]["password"]):
             session = Session()["username"] = username
             if session:
                 print("登录成功")
                 return True
             else:
                 print("登录失败:A")
                 return False
         else:
             print("登录失败:B")
             return False
     else:
         print("用户不存在")
         return False
예제 #3
0
def login():
    if not session.get('logged_in'):
        form = forms.LoginForm(request.form)
        if request.method == 'POST':
            username = request.form['username'].lower()
            password = request.form['password']
            if form.validate():
                #if helpers.credentials_valid(username, password):
                session['logged_in'] = True
                session['username'] = username
                return json.dumps({'status': 'Login successful'})
            #return json.dumps({'status': 'Invalid user/pass'})
            return json.dumps({'status': 'Both fields required'})
        return render_template('login.html', form=form)
    user = helpers.get_user()
    sskey = ""
    if 'keyword' in session:
        sskey = session["keyword"]
    simages = ""
    if 'imagePath' in session:
        if session['imagePath'] != "":
            imagePath = session['imagePath']
            print(imagePath)
            if (sskey == ""):
                return render_template("home.html", user=user)
            commonF = Common()
            simages = commonF.sprkSQLReadDFtoList(imagePath, sskey)

            sskey = "You are searching " + sskey
    return render_template('home.html',
                           user=user,
                           searchkey=sskey,
                           hists=simages)
    def __init__(self):
        self.api_key = 'AIzaSyC7SQ-1m0M6dN9L4E2aUhTM1ihAfTXIA0k '
        self.date_val = []
        self.date = []
        self.regex_val = ''

        self.result = {}

        self.keys = []
        self.values = []
        self.description = []

        self.name = Queue()
        self.actual_date = []
        self.date_val1 = []
        self.zip_code = []
        self.licence_id = ''
        self.regex_value = []
        self.code = ''
        self.first_name_original,self.last_name_original,self.middle_name_original,self.first_name_processed,self.last_name_processed,self.middle_name_processed={},{},{},{},{},{}
        self.regex_value,self.street,self.address,self.full_address=[],[],[],[]
        self.street_address_original,self.state_original,self.city_original,self.zip_code_original,self.street_address_processed,self.state_processed,self.city_processed,self.zip_code_processed={},{},{},{},{},{},{},{}
        self.failure_regex = ''
        self.c = Common()

        with open('../config/city.json', 'r') as data_file:
            self.cities = json.load(data_file)
        with open('../config/filtering.json', 'r') as data:
            self.state_value = json.load(data)
예제 #5
0
 def big_query(self, con, cur, query, data, limit_number=5000, debug=False):
     '''
     Change large number data of database,for insert、updata、delete.
     con--connection.
     cur--cursor.
     query--string.
     data--list ,it contains tuples,like [(1,'Tom'),(2,'Jack'),...].
     limit_number:int,the number of the query changes per times.
     debug--bool, True: print the running tips; Flase: print nothing.
     Example:
             con,cur = DB.connect()
             query ="INSERT INTO `test`.`user` (`id`,`name`) VALUES (%s,%s)"
             data = [(1,'Tom'),(2,'Jack')]
             running_query(con,cur,query,data)
     '''
     common = Common(debug=debug)
     data_current = []
     count = 0
     common.msg('Start to change data...\nTotal:%s' % len(data))
     for datum in data:
         count += 1
         data_current.append(datum)
         # [TIP]--Per limit_number rows to execute query once,or it's the last part--
         if len(data_current) % limit_number == 0 or count == len(data):
             cur.executemany(query, data_current)
             common.msg('Current change data:%s' % count)
             data_current = []
             # [NOTE]--You can commit later,but I think it's better here,especialy changing data more than 10000 rows--
             con.commit()
     # con.commit() #[NOTE]--Yes,I commited here before ,but it's disgusting when you break by some thing--
     common.msg('Change over!')
예제 #6
0
 def PurchaseCourse(self):
     if Users().JudgeLogin():
         if self.getUser(Users().CookieSession("sessionid")):
             with open(self.__DB_Order, "rb") as f:
                 if os.path.getsize(self.__DB_Order) == 0:
                     read = {}
                 else:
                     read = pickle.loads(f.read())
             self.getCourse()
             with open(self.__DB_Course, "rb") as f:
                 if os.path.getsize(self.__DB_Course) == 0:
                     reads = {}
                 else:
                     reads = pickle.loads(f.read())
             course = input("Course Name>>>").strip()
             if course in reads:
                 price = reads[course]["price"]
             else:
                 print("课程不存在")
                 return False
             data = {
                 "name": Users().CookieSession("sessionid"),
                 "course": course,
                 "price": price,
                 "createTime": time.time()
             }
             read[Common().Jam_hash(
                 str(time.time()) +
                 str(random.randint(10000, 99999)))] = data
             with open(self.__DB_Order, "wb") as f:
                 pickle.dump(read, f)
                 print("购买成功!")
                 return True
예제 #7
0
파일: User.py 프로젝트: yangyang0910/Python
 def Register(self, username, password, role):
     with open(self.__DB_User, "rb") as f:
         if os.path.getsize(self.__DB_User) == 0:
             read = {}
         else:
             read = pickle.loads(f.read())
     data = {
         "id": Common().Jam_hash(str(time.time())),
         "username": username,
         "password": Common().Jam_hash(password),
         "role": role
     }
     read[username] = data
     with open(self.__DB_User, "wb") as f:
         pickle.dump(read, f)
         return True
예제 #8
0
    def __init__(self, parent=None):
        super(MyWindow, self).__init__(parent)
        self.init_Ui()
        self.com = Common()
        self.title = [
            u"COUNT", u"CPU(%)", u"MEM(M)", u"FPS", u"Wifi下行(KB/S)",
            u"Wifi上行(KB/S)", u"下载流量(MB)", u"上传流量(MB)", u"Wifi总流量(MB)",
            u"移动网络下行(KB/S)", u"移动网络上行(KB/S)", u"下载流量(MB)", u"上传流量(MB)",
            u"移动网络总流量(MB)", u"温度", "Drawcall", u"电量"
        ]
        self.excel_path = "D:\PerfReport"
        # self.create_excel()
        self.getData = 0

        BufferSize = 1  #同时并发的线程数
        FpsS = QSemaphore(BufferSize)  # cpu并发锁
        CpuS = QSemaphore(0)
        DrawcallS = QSemaphore(0)
        NetS = QSemaphore(0)
        MemS = QSemaphore(0)
        TempS = QSemaphore(0)
        BatteryS = QSemaphore(0)
        TimeS = QSemaphore(0)
        self.lock = {}  #并发锁词典
        self.lock['cpu'] = CpuS
        self.lock['fps'] = FpsS
        self.lock['drawcall'] = DrawcallS
        self.lock['net'] = NetS
        self.lock['mem'] = MemS
        self.lock['temp'] = TempS
        self.lock['battery'] = BatteryS
        self.lock['time'] = TimeS
        self.dw = Draw()
        self.isCollect = 0
예제 #9
0
 def CreateSchool(self):
     name = input("校区名称>>>:")
     if Common().Write_Withs(self.__DB_School, name):
         print("创建成功")
         return True
     else:
         print("创建失败")
         return False
예제 #10
0
 def generateKey(self, mediaid, size=32):
     # Below: Do some black magic
     eq1 = int(int(math.floor(math.sqrt(6.9) * math.pow(2, 25))) ^ mediaid)
     eq2 = int(math.floor(math.sqrt(6.9) * math.pow(2, 25)))
     eq3 = (mediaid ^ eq2) ^ (mediaid ^ eq2) >> 3 ^ eq1 * 32
     # Below: Creates a 160-bit SHA1 hash
     shaHash = sha.new(self.createString([20, 97, 1, 2]) + str(eq3))
     finalHash = shaHash.digest()
     hashArray = Common().createByteArray(finalHash)
     # Below: Pads the 160-bit hash to 256-bit using zeroes, incase a 256-bit key is requested
     padding = [0] * 4 * 3
     hashArray.extend(padding)
     keyArray = [0] * size
     # Below: Create a string of the requested key size
     for i, item in enumerate(hashArray[:size]):
         keyArray[i] = item
     return Common().ByteArrayToString(keyArray)
예제 #11
0
 def setUp(self):
     print("--setUp")
     # Get the current file name which will be output to the log
     gloVar.caseName = os.path.basename(__file__)[:-3]
     # Initial automation script
     self.common = Common()
     gloVar.common = self.common
     self.common.timeOut(30)
예제 #12
0
 def __init__(self):
     self.common = Common()
     self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                   time.localtime())  # 存储Excel表格文件名编号
     self.db = "case"
     self.dboperate = DbOperate()
     self.windows = None
     self.report_path = ReadConfig().save_report()
     self.catlog = 1
예제 #13
0
def up_photo():
    img = request.files.get('photo')
    #username = request.form.get("name")
    if (not img):
        return redirect('/')
    if not (img and allowed_file(img.filename)):
        return jsonify({
            "error": 1001,
            "msg": "Only support .png .PNG .jpg .JPG .bmp .gif"
        })
    path = basedir + "/static/photo/"
    imgfilename = img.filename.encode("utf-8").decode("latin1")
    file_path = path + imgfilename
    img.save(file_path)
    '''
    encoded_string=""
    with open(file_path, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read())
    #print (encoded_string)
    '''
    imgType = imghdr.what(file_path)
    imagebase64 = base64.b64encode(open(file_path, 'rb').read())
    commonF = Common()
    #if (not commonF.sparkSQLIsRepeat('04122019203919021146.txt',str(imagebase64, 'utf-8'))):
    #    return redirect('/')
    x = commonF.readImageText(file_path, "all")
    x = re.sub('\s', '', x)
    x = x.replace('\n', '').replace(' ', '').replace('|', '')
    x = ("NoTag") if x == "" else (x.lower())
    sstring = img.filename + "|" + x + "|data:image/" + imgType + ";base64," + str(
        imagebase64, 'utf-8')
    nowstring = sstring.encode("utf-8").decode("latin1")

    print("here here here here")
    conf = SparkConf(
    )  #.setAppName("Upload One Image to HDFS").setMaster("yarn")
    #sc = SparkContext(conf=conf)
    sc = SparkContext.getOrCreate(conf=conf)
    sqlContext = SQLContext(sc)

    uploadedDF = sc.parallelize([
        (img.filename, x,
         "data:image/" + imgType + ";base64," + str(imagebase64, 'utf-8'))
    ]).toDF(["path", "features", "binary"])
    uploadedDF.write.mode('append').parquet(
        dataFrameUrl)  #("hdfs://gpu3:9000/dataFrames/final9")
    print(nowstring)
    #file = '04122019203919021146.txt'
    #with open(file, 'a+') as f:
    #    f.write(nowstring)
    #    f.write('\n')
    #    f.close()
    #   with hdfs.open('hdfs://gpu3:9000/wuxi/04122019203919021146.txt', 'a') as f:
    #       f.write(nowstring)
    #return render_template('home.html')
    return redirect('/')
예제 #14
0
def talker():
    calc = 'calculated'
    pub = rospy.Publisher('calc_done', String, queue_size=10)
    rospy.init_node('mapcalc', anonymous=True)
    common = Common()
    common.Init()
    common.Frame()
    if not rospy.is_shutdown():
        rospy.loginfo(calc)
        pub.publish(calc)
예제 #15
0
    def __init__(self, image_level=None):
        """ Builds the object

        Parameters
        ----------
        image_level : bool
            Whether using image-level dataset, set to False if using bounding boxes, by default is True
        """

        self.image_level = True if image_level is None else image_level
        self.common = Common(self.image_level)
 def __init__(self):
     try:
         self.__usrInpt = -1
         self.common = Common("KEY.txt", "ENC.txt")
         self.keyGeneration = KeyGeneration(self.common)
         self.encryption = Encryption(self.common)
         self.decryption = Decryption(self.common)
         self.breakEncryption = BreakEncryption(self.common)
     except Exception as ex:
         print("An error occurred while initializing class Main. Error: ",
               ex)
예제 #17
0
 def __init__(self, excel, sheet, workbook, interval, durtime, package,
              lock):
     super(QThread, self).__init__()
     self.excel = excel
     self.interval = interval
     self.durtime = durtime
     self.package = package
     self.sheet = sheet
     self.workbook = workbook
     self.btn_enable = False
     self.lock = lock
     self.com = Common()
예제 #18
0
    def callme(self):
        print "++++++++++++++++++++++ Regression Week 3: Polynomial Regression ++++++++++++++++++++++"
        cmnHandle = Common()
        df_train = cmnHandle.readcsv("../data/kc_house_train_data.csv")
        df_test = cmnHandle.readcsv("../data/kc_house_test_data.csv")

        tmp = np.array(range(3))
        print cmnHandle.polynomial_sframe(tmp, 3)

        poly1_data = cmnHandle.polynomial_sframe(df_train['sqft_living'], 1)

        print "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
예제 #19
0
 def __init__(self, excel, sheet, workbook, interval, durtime, package,
              lock):
     super(QThread, self).__init__()
     self.excel = excel
     self.interval = interval
     self.durtime = durtime
     self.package = package
     self.sheet = sheet
     self.workbook = workbook
     self.btn_enable = False
     self.lock = lock
     self.appData = Common.app_data(self)
     self.phoneModel = self.appData['phone_model']  #获取手机型号
     self.com = Common()
예제 #20
0
 def __init__(self):
     self.common = Common()
     # 登录
     self.common.driver = self.common.driver
     # Excel写入
     self.row = 0
     self.workbook = xlwt.Workbook(encoding='utf-8')
     self.booksheet = self.workbook.add_sheet('Sheet1')
     self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                   time.localtime())  # 存储Excel表格文件名编号
     # 每个案件的数量
     self.number = 1
     self.report_path = ReadConfig().save_report()
     self.dboperate = DbOperate()
     self.db = "case"
     self.catlog = 2
예제 #21
0
 def __init__(self):
     self.common = Common()
     # 登录
     self.driver = self.common.driver
     # Excel写入
     self.row = 0
     self.workbook = xlwt.Workbook(encoding='utf-8')
     self.booksheet = self.workbook.add_sheet('Sheet1')
     self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())  # 存储Excel表格文件名编号
     # 每个案件的数量
     self.number = 1
     self.report_path = ReadConfig().save_report()
     self.case_count = FunctionName.get_count
     self.excel_number(("案件名称", "案件号", "详情页价格", "下单页价格", "下单页总价格", "支付页总价格", "价格状态"))
     self.dboperate = DbOperate()
     self.windows = None
     self.db = "case"
예제 #22
0
def login():
    '''
    Login check
    '''
    if not session.get('logged_in'):
        form = forms.LoginForm(request.form)
        if request.method == 'POST':
            username = request.form['username'].lower()
            password = request.form['password']
            if form.validate():
                if helpers.credentials_valid(username, password):
                    session['logged_in'] = True
                    session['username'] = username
                    return json.dumps({'status': 'Login successful'})
                return json.dumps({'status': 'Invalid user/pass'})
            return json.dumps({'status': 'Both fields required'})
        return render_template('login.html', form=form)
    user = helpers.get_user()
    '''
    Return memems from HDFS

    Common.py is our core libray written by ourselves to use SparkSQL or do inner-text dection 
    Common.py can be seen in .../Flaskex/
    '''

    sskey = ""
    if 'keyword' in session:
        sskey = session["keyword"]
    simages = ""
    if 'imagePath' in session:
        if session['imagePath'] != "":
            imagePath = session['imagePath']
            print(imagePath)
            if (sskey == ""):
                return render_template("home.html", user=user)
            commonF = Common()
            # Common is written by ourselves to run SparkSQL
            simages = commonF.sprkSQLReadDFtoList(imagePath, sskey)
            # sprkSQLReadDFtoList is to get images from hdfs using SparkSQL
            sskey = "You are searching " + sskey
    return render_template('home.html',
                           user=user,
                           searchkey=sskey,
                           hists=simages)
예제 #23
0
 def __init__(self):
     super(Draw, self).__init__()
     self.com = Common()
예제 #24
0
 def __init__(self):
     self.objCommon = Common()
예제 #25
0
 def __MakeCookie(self, key):
     return Common().Jam_hash("cookie_" + key)
예제 #26
0
파일: demo.py 프로젝트: JasonJoke/apitools
#!/anaconda3/envs/FEALPy/bin python3.7
# -*- coding: utf-8 -*-
# ---
# @Software: PyCharm
# @Site:
# @File: demo.py
# @Author: JasonWu
# @E-mail: [email protected]
# @Time: 2月 24, 2020
# ---

from Common import Common

#登录页路由
uri = '/login'
# username变量存储用户名参数
username = '******'
# password变量存储密码参数
password = '******'
# 拼凑body的参数
payload = 'username='******'&password='******'Response内容:' + response_login.text)
예제 #27
0
def up_photo():

    '''
    For uploading photo into HDFS

    '''


    img = request.files.get('photo')
    #Get photo from webpage

    if (not img):
        return redirect('/')
    if not (img and allowed_file(img.filename)):
        return jsonify({"error": 1001, "msg": "Only support .png .PNG .jpg .JPG .bmp .gif"})

    '''
    If not supported images, return error
    
    ''' 

    path = basedir+"/static/photo/"
    imgfilename=img.filename.encode("utf-8").decode("latin1")
    file_path = path+imgfilename
    img.save(file_path)


    '''
    Save the image in local directory 
    '''

    imgType = imghdr.what(file_path)
    imagebase64 = base64.b64encode(open(file_path,'rb').read())
    commonF = Common()
    x=commonF.readImageText(file_path,"all")

    '''
    Get type, inner-text and base64 of that image 

    '''



    x=re.sub('\s','',x)
    x=x.replace('\n', '').replace(' ', '').replace('|','')
    x=("NoTag") if x == "" else (x.lower())
    sstring = img.filename +"|"+ x + "|data:image/" +imgType+";base64," + str(imagebase64, 'utf-8')
    nowstring=sstring.encode("utf-8").decode("latin1")
    
    conf = SparkConf()#.setAppName("Upload One Image to HDFS").setMaster("yarn")
    #sc = SparkContext(conf=conf)
    sc = SparkContext.getOrCreate(conf=conf)
    sqlContext = SQLContext(sc)
    
    uploadedDF = sc.parallelize( [ (img.filename,x,"data:image/" +imgType+";base64," + str(imagebase64, 'utf-8')) ]).toDF(["path","features","binary"])
    uploadedDF.write.mode('append').parquet(dataFrameUrl)  #("hdfs://gpu3:9000/dataFrames/final8")

    '''
    Save it into HDFS 
    '''
    print (nowstring)
    return redirect('/')
예제 #28
0
 def __init__(self):
     self.common = Common()
     self.timetemp = time.strftime("%Y-%m-%d-%H-%M-%S",
                                   time.localtime())  # 存储Excel表格文件名编号
     self.db = "case"
     self.dboperate = DbOperate()
예제 #29
0
def talker():
    common = Common()
    common.Init()
    common.Frame()
예제 #30
0
 def ReadSchool(self, add="北京校区"):
     return Common().Read_Withs(self.__DB_School)