def populate_datas(cls, logging=True):

        users = User.objects.all()
        total = User.objects.all().count()
        count = 0
        GameData.objects.all().delete()
        for user in users:
            count += 1
            if user.soup:
                soup = BeautifulSoup(user.soup, 'html.parser')
                s_tournaments = soup.find_all(class_='bowler-ind-tournament')
                if s_tournaments:
                    for s_tournament in s_tournaments:
                        tournament_url = s_tournament.find('h5').find('a').get('href')
                        try:
                            place = re.sub("[^0-9]", "", unicode(s_tournament.h6.string).split(' ')[0])

                        except:
                            place= 0
                            matches = []

                        matches = []
                        tr_matches = s_tournament.find_all('tr')[1:]
                        for tr_match in tr_matches:
                            tr_games = tr_match.find_all('td')
                            tr_games = tr_games[1:len(tr_games) - 2]
                            games = []
                            for tr_game in tr_games:
                                try:
                                    score = int(re.sub("[^0-9]", "", unicode(tr_game.string)))
                                    games.append(score)
                                except:
                                    score = 0

                            print(games)
                            matches.append(games)


                        tournament = cls.objects.filter(soup_url__icontains=tournament_url).first()
                        if place and tournament:
                            tournament_data = tournament.tournament_datas.filter(user=user).first()
                            if not tournament_data:
                                tournament_data = TournamentData.create(tournament, user)
                            tournament_data.place = int(place)
                            tournament_data.save()


                            match_number = 0
                            for games in matches:
                                game_number = 0
                                for game in games:
                                    game_data = GameData.create(tournament_data, game_number, match_number)
                                    game_data.total = game
                                    print(game)
                                    game_data.save()
                                    game_number += 1
                                match_number += 1
                            print(match_number, 'matches added for', user.first_name)

            print('Populating Tournament Datas (', count, '/', total, ')')
Exemple #2
0
	def _get_initial_query_dict(self, qdict):
		if not qdict:
			qdict = QueryDict(None, mutable=True)
		elif isinstance(qdict, QueryDict):
			qdict = qdict.copy()
		elif isinstance(qdict, basestring):
			if qdict.startswith('?'):
				qdict = qdict[1:]
			qdict = QueryDict(qdict, mutable=True)
		else:
			# Accept any old dict or list of pairs.
			try:
				pairs = qdict.items()
			except:
				pairs = qdict
			qdict = QueryDict(None, mutable=True)
			# Enter each pair into QueryDict object:
			try:
				for k, v in pairs:
					# Convert values to unicode so that detecting
					# membership works for numbers.
					if isinstance(v, (list, tuple)):
						for e in v:
							qdict.appendlist(k, unicode(e))
					else:
						qdict.appendlist(k, unicode(v))
			except:
				# Wrong data structure, qdict remains empty.
				pass
		return qdict
Exemple #3
0
    def upload(self, myFile):
        # 전송하고자 하는 파일을 선택하는 부분
        # --> 본 파일이 위치한 폴더 위치를 지정하거나 또는 임의의 폴더를 선택하도록 설정할 수 있음
        # upload_path = '/path/to/project/data/'
        upload_path = os.path.dirname(__file__)  # 임의의 폴더를 선택할 수 있도록 하는 부분

        # 업로드된 파일을 저장하고자 하는 파일명
        # 'saved.bin'으로 저장하도록 지정함
        # 만일 업로드된 파일 이름명 그대로 저장하고자 할 경우에는 아래와 같이 설정
        # upload_filename = myFile.filename
        upload_filename = 'saved.bin'

        upload_file = os.path.normpath(
            os.path.join(upload_path, upload_filename))
        size = 0

        html_out_text = ""

        with open(upload_file, 'wb') as out:
            while True:
                data = myFile.file.read(8192)
                if not data:
                    break
                out.write(data)
                html_out_text += unicode(data)
                print(data)
                size += len(data)
        out.close()

        self.Encrypt(upload_file)  # RSA 복호화 과정을 수행하는 함수 호출
Exemple #4
0
 def __init__(self):
     now = datetime.now()
     date = ('%s-%s-%s' % (now.year, now.month, now.day))
     url = "https://kmucoop.kookmin.ac.kr/menu/menujson.php?callback=jQuery172002718234401576014_1575532723347&sdate={date}&edate={date}&today={date}".format(
         date=date)
     response = requests.get(url)
     data = response.text
     data = unicode(data[42:-2])
     data = data.encode('utf-8')
     data = data.decode('unicode_escape')
     self.today_menu = data
     print(data)
Exemple #5
0
    def upload(self, myFile):
        # 전송하고자 하는 파일을 선택하는 부분
        # --> 본 파일이 위치한 폴더 위치를 지정하거나 또는 임의의 폴더를 선택하도록 설정할 수 있음
        # upload_path = '/path/to/project/data/'
        upload_path = os.path.dirname(__file__)  # 임의의 폴더를 선택할 수 있도록 하는 부분

        # 업로드된 파일을 저장하고자 하는 파일명
        # 'saved.bin'으로 저장하도록 지정함
        # 만일 업로드된 파일 이름명 그대로 저장하고자 할 경우에는 아래와 같이 설정
        # upload_filename = myFile.filename
        upload_filename = 'saved.bin'

        upload_file = os.path.normpath(
            os.path.join(upload_path, upload_filename))
        size = 0

        html_out_text = ""

        with open(upload_file, 'wb') as out:
            while True:
                data = myFile.file.read(8192)
                if not data:
                    break
                out.write(data)
                html_out_text += unicode(data)
                print(data)
                size += len(data)
        out.close()

        decrypted_message = self.Decrypt(upload_file)  # RSA 복호화 과정을 수행하는 함수 호출
        verify_message = Verify_DigSig_On_Hashed_File(
            'ForUpload/R_plaintext.txt',
            'ForUpload/KeyFile/alicepublickey.txt')

        webpage_output = """
                   <html>
                   <h1>OK. Received File...</h1>
                   <p>Let's Decrypt File Using Web Server's Private Key for RSA
                   <p>Filename: {}
                   <p>Length: {}
                   <p>Mime-type: {}
                   <p>Received Data: {}
                   <p>
                   <p>
                   <p>Decrypted Data: {}
                   <p>Verify_message: {}
                   </html>
                 """.format(myFile.filename, size, myFile.content_type,
                            html_out_text, decrypted_message, verify_message)
        # 결과를 리턴 --> 화면에 HTML 코드로 출력함...
        return webpage_output
Exemple #6
0
    def upload(self, myFile):

        # 전송하고자 하는 파일을 선택하는 부분
        # --> 본 파일이 위치한 폴더 위치를 지정하거나 또는 임의의 폴더를 선택하도록 설정할 수 있다.
        # upload_path = '/path/to/project/data/'
        upload_path = os.path.dirname(__file__)  # 임의의 폴더를 선택 할 수 있도록 한다.

        # 업로드된 파일을 저장하고자 하는 파일명
        # 'saved.bin'으로 저장하도록 지정함
        # 만일 업로드된 파일 이름명 그대로 저장하고자 할 경우에는 아래와 같이 설정
        # upload_filename = myFile.filename
        upload_filename = 'saved.bin'

        upload_file = os.path.normpath(
            os.path.join(upload_path, upload_filename))  # 유저가 저장한 파일을 그대로 불러들임
        size = 0

        html_out_text = ""

        with open(upload_file, 'wb') as out:
            while True:
                data = myFile.file.read(8192)
                if not data:
                    break
                out.write(data)
                html_out_text += unicode(data)
                print(data)
                size += len(data)
        out.close()

        decrypted_message = self.RSA_Decrypt(upload_file)

        webpage_output = """
                    <html>
                    <h1>OK. Received File...</h1>
                    <p>Let's Decrypt File Using Web Server's Private Key for RSA
                    <p>Filename: {}
                    <p>Length: {}
                    <p>Received Data: {}
                    <p>
                    <p>
                    <p>Decrypted Data: {}
                    <p>web decrypted message :{}
                    </html>
                    """.format(myFile.filename, size, myFile.content_type,
                               html_out_text, decrypted_message)
        # 결과를 리턴 ---> 화면에 HTML 코드로 출력함
        return webpage_output
Exemple #7
0
    def createPolicy(self, policy_string):
        """
         Convert a Boolean formula represented as a string into a policy represented like a tree.
        """

        assert type(policy_string) in [str, unicode
                                       ], "invalid type for policy_string"
        if (type(policy_string) == str):
            policy_string = unicode(policy_string)
        parser = PolicyParser()
        policy_obj = parser.parse(policy_string)
        _dictCount, _dictLabel = {}, {}
        parser.findDuplicates(policy_obj, _dictCount)
        for i in _dictCount.keys():
            if _dictCount[i] > 1: _dictLabel[i] = 0
        parser.labelDuplicates(policy_obj, _dictLabel)
        return policy_obj
Exemple #8
0
    def file_upload(self, ufile):
        # 전송하고자 하는 파일을 선택하는 부분
        # --> 본 파일이 위치한 폴더 위치를 지정하거나 또는 임의의 폴더를 선택하도록 설정할 수 있음
        #upload_path = '/path/to/project/data/'
        #upload_path = '/Users/brother/PycharmProjects/InventWithPython/CherryPy-By-Example-Code/Second-Example/'
        upload_path = os.path.dirname(__file__)   # 임의의 폴더를 선택할 수 있도록 하는 부분 (현재 이것이 실행되고 있는 폴더에 저장 된다.)

        # 업로드된 파일을 저장하고자 하는 파일명
        # 'saved.txt'로 저장하도록 지정
        # 만일 업로드된 파일 이름명 그대로 저장하고자 할 경우에는 아래와 같이 설정
        # upload_filename = ufile.filename
        upload_filename = 'saved.txt'

        upload_file = os.path.normpath(os.path.join(upload_path, upload_filename))
        size = 0

        html_out_text = ""

        with open(upload_file, 'wb') as out:
            while True:
                data = ufile.file.read(8192)# 8192bit 만큼을 읽어서 저장 한다.
                if not data:
                    break
                out.write(data)
                html_out_text += unicode(data)
                print(data)
                size += len(data)
        out.close()
        webpage_output = """
                <html>
                <p>File received.
                <p>Filename: {}
                <p>Length: {}
                <p>Mime-type: {}
                <p>Data: {}
                </html>
              """.format(ufile.filename, size, ufile.content_type, html_out_text)

        #.format()
        # ex)
        # name = 'lee'
        # "ffwaf {} ".format(name)
        # ffwaf lee 가 출력됨

        return webpage_output
Exemple #9
0
    def upload_AES_File(self, myFile):
        global seed_number
        # upload_path = '/path/to/project/data/'
        upload_path = os.path.dirname(__file__)  # 임의의 폴더를 선택할 수 있도록 하는 부분

        # 업로드된 파일을 저장하고자 하는 파일명        # 'saved.bin'으로 저장하도록 지정함
        upload_filename = 'saved_AES.bin'

        upload_file = os.path.normpath(
            os.path.join(upload_path, upload_filename))
        size = 0

        html_out_text = ""

        with open(upload_file, 'wb') as out:
            while True:
                data = myFile.file.read(8192)
                if not data:
                    break
                out.write(data)
                html_out_text += unicode(data)
                print(data)
                size += len(data)
        out.close()

        decrypted_message = self.AES_Decrypt(
            upload_file, seed_number)  # RSA 복호화 과정을 수행하는 함수 호출

        webpage_output = """
                    <html>
                    <h1>OK. Received File...</h1>
                    <p>Let's Decrypt File...
                    <p>Filename: {}
                    <p>Length: {}
                    <p>Mime-type: {}
                    <p>Received Data: {}
                    <p>
                    <p>
                    <p>Decrypted Data: {}
                    </html>
                  """.format(myFile.filename, size, myFile.content_type,
                             html_out_text, decrypted_message)
        # 결과를 리턴 --> 화면에 HTML 코드로 출력함...
        return webpage_output
Exemple #10
0
	def _process_list(self, current_list, op, val):
		if not val:
			if op == '=':
				return []
			else:
				return current_list
		# Deal with lists only.
		if not isinstance(val, (list, tuple)):
			val = [val]
		val = [unicode(v) for v in val]
		# Remove
		if op == '-':
			for v in val:
				while v in current_list:
					current_list.remove(v)
		# Replace
		elif op == '=':
			current_list = val
		# Add
		elif op == '+':
			for v in val:
				current_list.append(v)
		return current_list
Exemple #11
0
     def getdata(self):  # Idea taken from the Python Cookbook
         self.rates = {}
         try:
             date = "Unknown"
             fh = urllib.request.urlopen("https://www.bankofcanada.ca/valet/observations/group/FX_RATES_DAILY/csv?start_date=2017-01-03")
             print(fh.read())
             #  print(type(fh.read))
             # fh= urllib.("https://www.bankofcanada.ca/valet/observations/group/FX_RATES_DAILY/csv?start_date=2017-01-03")


             openFile= open('FX_RATES_DAILY-sd-2017-01-03.csv', 'r')

             for line in openFile:

                if not line or line.startswith("#") or line.startswith("Closing "):

                     continue


                fields = line.split(",")

                # print('Line: ', line)
                # print('Campos: ', fields)


                if line.startswith('"date"'):
                    dateTemp = fields


                if line.startswith('"2020-04-13"'):

                     date = fields[0]
                     # print('DATE: ', date)
                     lineTemp= line

                     try:
                         # fields = line.split(",")

                         for field in fields:
                             pass
                         try:

                             count= 0
                             for temp in fields:

                                field= temp.replace('"', "")
                                if field not in '2020-04-13' and field not in '' and field not in '\n':
                                    # print("Type Field", type(field))
                                    # print('FIELD: ', field)


                                    count= count+1
                                    value = float(field)
                                    self.rates[unicode(dateTemp[count])] = value


                         except ValueError as g:
                             print('G', g)

                     except ValueError as f:
                         print('F', f)
                         pass


                '''

                else:
                    try:
                        print('Fields -1: ', value)
                        value = float(fields[-1])
                        
                        self.rates[unicode(fields[0])] = value
                    except ValueError as f:
                        print(f)
                        pass
                 '''

             return "Exchange Rates Date: " + date
         except Exception as e:
            return "Failed to download:\n%s" % e
Exemple #12
0
 def updateUi(self):
     to = unicode(self.toComboBox.currentText())
     from_ = unicode(self.fromComboBox.currentText())
     amount = (self.rates[from_] / self.rates[to]) * self.fromSpinBox.value()
     self.toLabel.setText("%0.2f" % amount)
Exemple #13
0
def no_accent_vietnamese(s):
    s = re.sub(u'Đ', 'D', s)
    s = re.sub(u'đ', 'd', s)
    return unicodedata.normalize('NFKD', unicode(s)).encode('ASCII', 'ignore')
 price = price.replace(r'元/m2', '')
 price = int(price)
 total = float(total)
 print("{0} {1} {2} {3}".format(date, name, price, total))
 # 写入mysql数据库
 if database == "mysql":
     db.query('INSERT INTO loupan (city, date, name, price, total) '
              'VALUES(:city, :date, :name, :price, :total)',
              city=city_ch, date=date, name=name, price=price, total=total)
 # 写入mongodb数据库
 elif database == "mongodb":
     data = dict(city=city_ch, date=date, name=name, price=price, total=total)
     collection.insert(data)
 elif database == "excel":
     if not PYTHON_3:
         worksheet.write_string(row, col, unicode(city_ch, 'utf-8'))
         worksheet.write_string(row, col + 1, date)
         worksheet.write_string(row, col + 2, unicode(name, 'utf-8'))
         worksheet.write_number(row, col + 3, price)
         worksheet.write_number(row, col + 4, total)
     else:
         worksheet.write_string(row, col, city_ch)
         worksheet.write_string(row, col + 1, date)
         worksheet.write_string(row, col + 2, name)
         worksheet.write_number(row, col + 3, price)
         worksheet.write_number(row, col + 4, total)
     row += 1
 elif database == "json":
     data = dict(city=city_ch, date=date, name=name, price=price, total=total)
     datas.append(data)
 elif database == "csv":
Exemple #15
0
from datetime import datetime

import numpy
import pyparsing

a = numpy.unicode(datetime.now())
b = pyparsing.unicode(datetime.now())

print(a, type(a))
print(b, type(b))
Exemple #16
0
def to_unicode_or_bust(obj, encoding="latin1"):
    if isinstance(obj, basestring):
        if not isinstance(obj, unicode):
            obj = unicode(obj, encoding)
    return obj
         pic=pic)
 # 写入mongodb数据库
 elif database == "mongodb":
     data = dict(city=city_ch,
                 date=date,
                 district=district,
                 area=area,
                 name=name,
                 price=price,
                 desc=desc,
                 pic=pic)
     collection.insert(data)
 elif database == "excel":
     if not PYTHON_3:
         worksheet.write_string(row, col,
                                unicode(city_ch, 'utf-8'))
         worksheet.write_string(row, col + 1, date)
         worksheet.write_string(row, col + 2,
                                unicode(district, 'utf-8'))
         worksheet.write_string(row, col + 3,
                                unicode(area, 'utf-8'))
         worksheet.write_string(row, col + 4,
                                unicode(name, 'utf-8'))
         worksheet.write_number(row, col + 5, price)
         worksheet.write_string(row, col + 6,
                                unicode(desc, 'utf-8'))
         worksheet.write_number(row, col + 7,
                                unicode(pic, 'utf-8'))
     else:
         worksheet.write_string(row, col, city_ch)
         worksheet.write_string(row, col + 1, date)
Exemple #18
0
    f.close()

    if data[0:12] != "\x40\x15\x00\x00\x44\x43\x53\x01\x01\x00\x00\x00":
        print("确认你选择的是搜狗(.scel)词库?")

    #print("词库名:", byte2str(data[0x130 : 0x338]))#.encode('GB18030')
    #print("词库类型:", byte2str(data[0x338 : 0x540])) #.encode('GB18030')
    #print("描述信息:", byte2str(data[0x540 : 0xd40])) #.encode('GB18030')
    #print("词库示例:", byte2str(data[0xd40 : startPy])) #.encode('GB18030')

    getPyTable(data[startPy:startChinese])
    getChinese(data[startChinese:])


if __name__ == '__main__':
    #将要转换的词库添加在这里就可以了
    o = ['word/症状.scel', 'word/西医病名.scel']
    for f in o:
        deal(f)

    #保存结果
    f = open('word/sougou.txt', 'w', encoding='utf-8')
    for count, py, word in GTable:
        #GTable保存着结果,是一个列表,每个元素是一个元组(词频,拼音,中文词组),有需要的话可以保存成自己需要个格式
        f.write(
            unicode('{%(count)s}' % {
                'count': count
            } + py + ' ' + word).encode('GB18030'))  #最终保存文件的编码,可以自给改
        f.write('\n')
    f.close()
    def traverse(node):
        pos = len(json_tree)
        json_node = {}
        json_tree.append(json_node)
        json_node['type'] = type(node).__name__
        children = []
        if isinstance(node, ast.Name):
            json_node['value'] = node.id
        elif isinstance(node, ast.Num):
            json_node['value'] = unicode(node.n)
        elif isinstance(node, ast.Str):
            json_node['value'] = node.s
        elif isinstance(node, ast.alias):
            json_node['value'] = unicode(node.name)
            if node.asname:
                children.append(gen_identifier(node.asname))
        elif isinstance(node, ast.FunctionDef):
            json_node['value'] = unicode(node.name)
        elif isinstance(node, ast.ClassDef):
            json_node['value'] = unicode(node.name)
        elif isinstance(node, ast.ImportFrom):
            if node.module:
                json_node['value'] = unicode(node.module)
        elif isinstance(node, ast.Global):
            for n in node.names:
                children.append(gen_identifier(n))
        elif isinstance(node, ast.keyword):
            json_node['value'] = unicode(node.arg)

        # Process children.
        if isinstance(node, ast.For):
            children.append(traverse(node.target))
            children.append(traverse(node.iter))
            children.append(traverse_list(node.body, 'body'))
            if node.orelse:
                children.append(traverse_list(node.orelse, 'orelse'))
        elif isinstance(node, ast.If) or isinstance(node, ast.While):
            children.append(traverse(node.test))
            children.append(traverse_list(node.body, 'body'))
            if node.orelse:
                children.append(traverse_list(node.orelse, 'orelse'))
        elif isinstance(node, ast.With):
            children.append(traverse_list(node.body, 'body'))
        elif isinstance(node, ast.arguments):
            children.append(traverse_list(node.args, 'args'))
            children.append(traverse_list(node.defaults, 'defaults'))
            if node.vararg:
                children.append(gen_identifier(str(node.vararg), 'vararg'))
            if node.kwarg:
                children.append(gen_identifier(str(node.kwarg), 'kwarg'))
        elif isinstance(node, ast.ExceptHandler):
            if node.type:
                children.append(traverse_list([node.type], 'type'))
            if node.name:
                children.append(traverse_list([node.name], 'name'))
            children.append(traverse_list(node.body, 'body'))
        elif isinstance(node, ast.ClassDef):
            children.append(traverse_list(node.bases, 'bases'))
            children.append(traverse_list(node.body, 'body'))
            children.append(traverse_list(node.decorator_list, 'decorator_list'))
        elif isinstance(node, ast.FunctionDef):
            children.append(traverse(node.args))
            children.append(traverse_list(node.body, 'body'))
            children.append(traverse_list(node.decorator_list, 'decorator_list'))
        else:
            # Default handling: iterate over children.
            if type(node) is str:
                return pos
            for child in ast.iter_child_nodes(node):
                if isinstance(child, ast.expr_context) or isinstance(child, ast.operator) or isinstance(child,
                                                                                                        ast.boolop) or isinstance(
                        child, ast.unaryop) or isinstance(child, ast.cmpop):
                    # Directly include expr_context, and operators into the type instead of creating a child.
                    json_node['type'] = json_node['type'] + type(child).__name__
                else:
                    children.append(traverse(child))
        if isinstance(node, ast.Attribute):
            children.append(gen_identifier(node.attr, 'attr'))
        if (len(children) != 0):
            json_node['children'] = children
        return pos
Exemple #20
0
 sale = int(sale)
 print("{0} {1} {2} {3} {4} {5}".format(date, district, area, name, price, sale))
 # 写入mysql数据库
 if database == "mysql":
     db.query('INSERT INTO xiaoqu (city, date, district, area, name, price, sale) '
              'VALUES(:city, :date, :district, :area, :name, :price, :sale)',
              city=city_ch, date=date, district=district, area=area, name=name, price=price,
              sale=sale)
 # 写入mongodb数据库
 elif database == "mongodb":
     data = dict(city=city_ch, date=date, district=district, area=area, name=name, price=price,
                 sale=sale)
     collection.insert(data)
 elif database == "excel":
     if not PYTHON_3:
         worksheet.write_string(row, col, unicode(city_ch, 'utf-8'))
         worksheet.write_string(row, col + 1, date)
         worksheet.write_string(row, col + 2, unicode(district, 'utf-8'))
         worksheet.write_string(row, col + 3, unicode(area, 'utf-8'))
         worksheet.write_string(row, col + 4, unicode(name, 'utf-8'))
         worksheet.write_number(row, col + 5, price)
         worksheet.write_number(row, col + 6, sale)
     else:
         worksheet.write_string(row, col, city_ch)
         worksheet.write_string(row, col + 1, date)
         worksheet.write_string(row, col + 2, district)
         worksheet.write_string(row, col + 3, area)
         worksheet.write_string(row, col + 4, name)
         worksheet.write_number(row, col + 5, price)
         worksheet.write_number(row, col + 6, sale)
     row += 1