Example #1
0
 def filter_video_file(self, file_name, to_db, defaults=dict(),restrictions=dict()):
     with codecs.open(self.match, "w", encoding="utf-8") as matched,codecs.open(self.error, "w", encoding="utf-8") as error,codecs.open(file_name, "r", encoding="utf-8") as infile:
         results = []
         for title in infile.read().split("\n"):
             result = self.pattern.match(title)
             if result:
                 accepted = True
                 r_dict = result.groupdict()
                 self.fix_r_dict(r_dict,defaults)
                 r_dict["text"] = title
                 for key in restrictions.keys():
                     if restrictions[key] != r_dict[key]:
                         print(title+" MATCH FAIL: "+key,file=error)
                         print("error")
                         accepted = False
                         break
                 if accepted:
                     results.append(r_dict)
                     print(print_format.format(r_dict["tourny"],
                                               r_dict["tag1"],
                                               r_dict["chars1"],
                                               r_dict["tag2"],
                                               r_dict["chars2"],
                                               r_dict["round"],
                                               r_dict["game"]), 
                     
                     file = matched) 
             else:
                 print(title, file = error)
         if to_db:
             updates = serverset.build_inserts(results)
             serverset.make_update(updates)
         else:
             return results
Example #2
0
def print_file(file_name):
    with codecs.open(file_name, "r", encoding="utf-8") as infile:
        n = 0
        for line in infile.read().split("\n"):
            if n>10000:
                break
            print(line)
            n+=1
Example #3
0
def print_file(file_name):
    with codecs.open(file_name, "r", encoding="utf-8") as infile:
        n = 0
        for line in infile.read().split("\n"):
            if n > 10000:
                break
            print(line)
            n += 1
Example #4
0
def appendStringToFile(content, file):
    if os.path.exists(file):
        # ensure that we can write the file
        os.chmod(file, 0644)
    # write the string
    #f=open(file, "w")
    f = codecs.open(file, 'a+', encoding='utf-8')    
    f.write(content)
    f.close()
Example #5
0
def renew_info(data_file):
    with codecs.open(data_file, "r", encoding="utf-8") as videos:
        updates = []
        for line in videos.read().split("\n"):
            row = line.split("\t")
            updates.append(
                update_names_template.format(request_p1=sanitize(row[PLAYER1]),
                                             request_p2=sanitize(row[PLAYER2]),
                                             video_id=row[VIDEO]))
        make_update(updates)
Example #6
0
def writeStringToFile(content, file, encoding="utf-8", gzip=False):
    if os.path.exists(file):
        # ensure that we can write the file
        os.chmod(file, 0644)
    # write the string
    f=codecs.open(file, "w", encoding)
    #f = open(file,'a+')    
    f.write(content)
    f.close()
    if gzip:
        compressFile(file)
Example #7
0
def renew_info(data_file):
    with codecs.open(data_file,"r",encoding="utf-8") as videos:
        updates = []
        for line in videos.read().split("\n"):
            row = line.split("\t")
            updates.append(update_names_template.format(request_p1=sanitize(row[PLAYER1]),
                                                        request_p2=sanitize(row[PLAYER2]),
                                                        video_id=row[VIDEO]
                                                        
                                                        ))
        make_update(updates)
Example #8
0
 def __init__(self, filename, mode='a', encoding=None):
     """Handler constructor."""
     if codecs is None:
         encoding = None
     if encoding is None:
         stream = open(filename, mode)
     else:
         stream = codecs.open(filename, mode, encoding)
     RawStreamHandler.__init__(self, stream)
     # keep the absolute path, otherwise derived classes which use this
     # may come a cropper when the current directory changes
     self.baseFilename = os.path.abspath(filename)
     self.mode = mode
Example #9
0
 def filter_video_file(self,
                       file_name,
                       to_db,
                       defaults=dict(),
                       restrictions=dict()):
     with codecs.open(self.match, "w",
                      encoding="utf-8") as matched, codecs.open(
                          self.error, "w",
                          encoding="utf-8") as error, codecs.open(
                              file_name, "r", encoding="utf-8") as infile:
         results = []
         for title in infile.read().split("\n"):
             result = self.pattern.match(title)
             if result:
                 accepted = True
                 r_dict = result.groupdict()
                 self.fix_r_dict(r_dict, defaults)
                 r_dict["text"] = title
                 for key in restrictions.keys():
                     if restrictions[key] != r_dict[key]:
                         print(title + " MATCH FAIL: " + key, file=error)
                         print("error")
                         accepted = False
                         break
                 if accepted:
                     results.append(r_dict)
                     print(print_format.format(
                         r_dict["tourny"], r_dict["tag1"], r_dict["chars1"],
                         r_dict["tag2"], r_dict["chars2"], r_dict["round"],
                         r_dict["game"]),
                           file=matched)
             else:
                 print(title, file=error)
         if to_db:
             updates = serverset.build_inserts(results)
             serverset.make_update(updates)
         else:
             return results
Example #10
0
 def filter_video_list(self, video_list, to_db):
     #should an in place list modify be done?
     with codecs.open(self.error, "a", encoding="utf-8") as error:
         results = []
         for title in video_list:
             result = self.pattern.match(title)
             if result:
                 r_dict = result.groupdict()
                 r_dict["game"] = self.get_name(result)
                 results.append(r_dict)
             else:
                 print(title, file=error)
         if to_db:
             serverset.build_inserts(results)
         else:
             return results
Example #11
0
 def filter_video_list(self, video_list, to_db):
     #should an in place list modify be done?
     with codecs.open(self.error, "a", encoding="utf-8") as error:
         results = []
         for title in video_list:
             result = self.pattern.match(title)
             if result:
                 r_dict = result.groupdict()
                 r_dict["game"] = self.get_name(result)
                 results.append(r_dict)
             else:
                 print(title, file=error)
         if to_db:
             serverset.build_inserts(results)
         else:
             return results
Example #12
0
def to_file(game_list):

    with codecs.open(CHANNELNAME, "a+", encoding="utf-8") as infile:
        n = 0
        for game in game_list:
            try:
                print("{title}\tVideo:{videoId}\tChannel:{channelId}".format(
                    title=game["title"],
                    videoId=game["id"],
                    channelId=game["channelId"]),
                      file=infile)

            except UnicodeError:
                print(str(n), file=infile)
                print("Added video")
                n += 1

        print(n)
    print("Finished adding")
Example #13
0
    def __format_citydata(self):

        outjs = {}

        with open('../res/2345_city.txt') as f:

            lines = f.read().split('\n')
            provqx = [x for x in lines if 'provqx' in x and 'var' not in x]

            for item in provqx:

                item1 = item.split('=')[1]
                item1 = item1[1:-1]
                citys = re.split('[,]', item1)
                citys = [x[1:-1] for x in citys]

                for citys1 in citys:
                    for citem in citys1.split('|'):
                        citemsplits = re.split('[ -]', citem)
                        outjs[citemsplits[2]] = citemsplits[0]

        with codecs.open('../res/2345_city_json.txt', 'w',
                         encoding='utf-8') as f:
            f.write(json.dumps(outjs, indent=4, ensure_ascii=False))
Example #14
0
def renew_info(data_file):
    with codecs.open(data_file, "r", encoding="utf-8") as videos:
        updates = []
        for line in videos.read().split("\n"):
            row = line.split("\t")
            video_id = row[7]