def test_zg2uni(self): print("converting Zawgyi to Unicode") converted = Rabbit.zg2uni(u"မဂၤလာပါ") self.assertEqual(converted, u"မင်္ဂလာပါ") converted = Rabbit.zg2uni(u"ျပင္သစ္ဘာသာကီးဘုတ္") self.assertEqual(converted, u"ပြင်သစ်ဘာသာကီးဘုတ်")
def fetch(self, country_id): fetch_state = False scope = ['https://spreadsheets.google.com/feeds'] credentials = ServiceAccountCredentials.from_json_keyfile_name( 'client-secret.json', scope) sh = gspread.authorize(credentials).open_by_key( '1SjJG2RzITf8qAmYDU9RFnWVaMP9912y8KfbuJe8th-c') country_id = str(country_id) for ws_count, worksheet in enumerate(sh.worksheets()): # TODO write State By Country Here state_district = seeds.get_state_name(worksheet.title) state_name = "{0}/{1}".format(state_district[0], state_district[1]) state_id = str(uuid.uuid4().hex) state = State(id=state_id, object_id=state_id, country_id=str(country_id), name_mm_uni=str(state_name), name_mm_zawgyi=Rabbit.uni2zg(state_name)) cal_day_list = worksheet.col_values(1) hij_day_list = worksheet.col_values(2) sehri_time_list = worksheet.col_values(3) iftari_time_list = worksheet.col_values(4) db_session.add(state) db_session.commit() for i, (cal_day, hij_day, seh_time, iftar_time) in enumerate( zip(cal_day_list, hij_day_list, sehri_time_list, iftari_time_list)): if i is not 0: article_id = str(uuid.uuid4().hex) article = Day( id=article_id, object_id=article_id, country_id=str(country_id), state_id=str(state.object_id), day=i, day_mm=str(seeds.get_mm_num(i)), sehri_time=str(seh_time + " am"), sehri_time_desc="Sehri", calendar_day=str(cal_day), hijari_day=str(hij_day), sehri_time_desc_mm_zawgyi=Rabbit.uni2zg("ဝါချည်ချိန်"), sehri_time_desc_mm_uni="ဝါချည်ချိန်", iftari_time=str(iftar_time + " pm"), dua_mm_uni=Rabbit.zg2uni(seeds.daily_dua(i)["dua_mm"]), dua_mm_zawgyi=Rabbit.uni2zg( seeds.daily_dua(i)["dua_mm"]), dua_ar=seeds.daily_dua(i)["dua_ar"], dua_en=seeds.daily_dua(i)["dua_en"], iftari_time_desc="Iftari", iftari_time_desc_mm_zawgyi=Rabbit.uni2zg("ဝါဖြေချိန်"), iftari_time_desc_mm_uni="ဝါဖြေချိန်") db_session.add(article) db_session.commit() fetch_state = True return fetch_state
def fetch(self, country_id): fname = join(dirname(dirname(abspath(__file__))), 'ramdhan-api/data', 'ramadan_timetable_sheet.xlsx') work_book = xlrd.open_workbook(fname) country_id = str(country_id) for ws_count, worksheet in enumerate(work_book.sheet_names()): # TODO write State By Country Here state_district = seeds.get_state_name(worksheet) state_name = "{0}/{1}".format(state_district[0], state_district[1]) state_id = str(uuid.uuid4().hex) state = State(id=state_id, object_id=state_id, country_id=str(country_id), name_mm_uni=str(state_name), name_mm_zawgyi=Rabbit.uni2zg(state_name)) sheet = work_book.sheet_by_index(ws_count) cal_day_list = sheet.col_values(0) hij_day_list = sheet.col_values(1) sehri_time_list = sheet.col_values(2) iftari_time_list = sheet.col_values(3) db_session.add(state) db_session.commit() for i, (cal_day, hij_day, seh_time, iftar_time) in enumerate( zip(cal_day_list, hij_day_list, sehri_time_list, iftari_time_list)): if i is not 0: article_id = str(uuid.uuid4().hex) article = Day( id=article_id, object_id=article_id, country_id=str(country_id), state_id=str(state.object_id), day=i, day_mm=str(seeds.get_mm_num(i)), sehri_time=str(str(seh_time).strip() + " am"), sehri_time_desc="Sehri", calendar_day=str(date[i - 1]), hijari_day=str(hij_day).strip(), sehri_time_desc_mm_zawgyi=Rabbit.uni2zg("ဝါချည်ချိန်"), sehri_time_desc_mm_uni="ဝါချည်ချိန်", iftari_time=str(str(iftar_time).strip() + " pm"), dua_mm_uni=Rabbit.zg2uni(seeds.daily_dua(i)["dua_mm"]), dua_mm_zawgyi=Rabbit.uni2zg( seeds.daily_dua(i)["dua_mm"]), dua_ar=seeds.daily_dua(i)["dua_ar"], dua_en=seeds.daily_dua(i)["dua_en"], iftari_time_desc="Iftari", iftari_time_desc_mm_zawgyi=Rabbit.uni2zg("ဝါဖြေချိန်"), iftari_time_desc_mm_uni="ဝါဖြေချိန်") db_session.add(article) db_session.commit() fetch_state = True return fetch_state
def convert(self): """ To handle the convert button press event """ zg_input = self.root.ids.zawgyi_text uni_input = self.root.ids.unicode_text mode = "u" if uni_input.text != "" else "z" # If Unicode text input is entered then, convert it to Zawgyi if mode == "u": result = Rabbit.uni2zg(uni_input.text) zg_input.text = result elif mode == "z": result = Rabbit.zg2uni(zg_input.text) uni_input.text = result
def test_mm_num_gen(self): all_day = db_session.query( Day).filter(Day.id!=None).all() for i,r_day in enumerate(all_day): print(i) print(r_day.day) r_day.sehri_time_desc="Sehri" r_day.sehri_time_desc_mm_zawgyi=Rabbit.uni2zg("ဝါချည်ချိန်") r_day.sehri_time_desc_mm_uni="ဝါချည်ချိန်" from seeds import daily_dua r_day.dua_mm_uni=Rabbit.zg2uni(str(daily_dua(r_day.day)["dua_mm"])) r_day.dua_mm_zawgyi=daily_dua(r_day.day)["dua_mm"] r_day.dua_ar=daily_dua(r_day.day)["dua_ar"] r_day.dua_en=daily_dua(r_day.day)["dua_en"] r_day.iftari_time_desc="Iftari" r_day.iftari_time_desc_mm_zawgyi=Rabbit.uni2zg("ဝါဖြေချိန်") r_day.iftari_time_desc_mm_uni="ဝါဖြေချိန်" db_session.commit() print(all_day)
def test_zg2uni(self): print("converting Zawgyi to Unicode") converted = Rabbit.zg2uni(u"မဂၤလာပါ") self.assertEqual(converted, u"မင်္ဂလာပါ")
def ConvFun(self): print(self.UserInput) self.my_file = ntpath.basename(str(self.UserInput)) #print(self.my_file) self.my_file2 = ntpath.dirname(str(self.UserInput)) #print(self.my_file2) self.base = os.path.splitext(self.my_file)[0] #print(self.base) self.WORD_NAMESPACE = '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}' self.PARA = self.WORD_NAMESPACE + 'p' self.TEXT = self.WORD_NAMESPACE + 't' self.path = ntpath.dirname(str(self.UserInput)) f = open(self.path + '\\' + "replace.csv", 'w+', encoding='utf8') self.Document = ZipFile(self.my_file2 + '\\' + self.my_file) self.xml_content = self.Document.read('word/document.xml') self.Document.close() self.tree = XML(self.xml_content) for self.paragraph in self.tree.getiterator(self.PARA): for self.node in self.paragraph.getiterator(self.TEXT): if self.node.text: self.u_conv_word = str(Rabbit.zg2uni(self.node.text)) print(self.u_conv_word) print(self.node.text) f.write("{0},{1}\n".format(self.node.text, self.u_conv_word)) f.close() os.rename(self.my_file2 + '\\' + self.my_file, self.my_file2 + '\\' + self.base + '.zip') with ZipFile(self.my_file2 + '\\' + self.base + str(".zip"), 'r') as zipObj: zipObj.extractall(self.my_file2 + '\\' + self.base) print(self.my_file2 + '\\' + self.base) self.counter = 0 xml_filename_original = self.my_file2 + '\\' + self.base + '\\word\\' + "document.xml" xml_filename_new = xml_filename_original.replace(".xml", "_new.xml") find_and_replace_filename = self.my_file2 + '\\' + "replace.csv" xml_file_original = open(xml_filename_original, "r", encoding='utf-8') xml_file_new = open(xml_filename_new, "w", encoding='utf-8') with open(find_and_replace_filename, "r", encoding='utf-8') as f: for line in xml_file_original: f.seek(0) reader = csv.reader(f) next(reader, None) for row in reader: line_old = line line_new = line.replace(row[0], row[1]) if line_new != line_old: line = line_new self.counter += 1 print("Counter: " + str(self.counter)) xml_file_new.write(line) xml_file_original.close() xml_file_new.close() shutil.copy( self.path + '\\' + self.base + '\\word\\' + "document_new.xml", self.path + '\\' + self.base + '\\word\\' + "document.xml") zf = ZipFile("%s.zip" % (self.my_file2 + '\\' + self.base), "w", ZIP_DEFLATED) abs_src = os.path.abspath(self.my_file2 + '\\' + self.base) for dirname, subdirs, files in os.walk(self.my_file2 + '\\' + self.base): for filename in files: absname = os.path.abspath(os.path.join(dirname, filename)) arcname = absname[len(abs_src) + 1:] print('zipping %s as %s' % (os.path.join(dirname, filename), arcname)) zf.write(absname, arcname) zf.close() os.rename(self.my_file2 + '\\' + self.base + ".zip", self.my_file2 + '\\' + self.base + '_Uni.docx') print("Done") os.remove(self.path + '\\' + "replace.csv") shutil.rmtree(self.path + '\\' + self.base)
def gen_seeds(): import uuid from database import db_session from manage import Country, State, Day source_arr = [{ "base_url": "http://androidweekly.net/issues/", "name": "Myanmar", "tag": "android" }] state_arr = [ "ရန်ကုန်တိုင်း", "မန္တလေးတိုင်း", "ဧရာဝတီတိုင်း", "မကွေးတိုင်း", "စစ်ကိုင်းတိုင်း", "တင်္နသာရီတိုင်း", "ပဲခူးတိုင်း", "ကချင်ပြည်နယ်", "ချင်းပြည်နယ်", "ရခိုင်ပြည်နယ်", "ရှမ်းပြည်နယ်", "ကယားပြည်နယ်", "ကရင်ပြည်နယ်", "မွန်ပြည်နယ်" ] for s in source_arr: print("Generating Country.......\n\n\n") country_id = str(uuid.uuid4().hex) country = Country(id=country_id, object_id=country_id, name=str(s["name"])) db_session.add(country) db_session.commit() if os.environ["ENV"] != 'production': for state in state_arr: print("Generating State.........\n\n") issue_id = str(uuid.uuid4().hex) issue = State(id=issue_id, object_id=issue_id, country_id=str(country.object_id), name_mm_uni=str(state), name_mm_zawgyi=Rabbit.uni2zg(state)) db_session.add(issue) db_session.commit() for art in range(1, 31): print("Generating Days.......\n") article_id = str(uuid.uuid4().hex) article = Day( id=article_id, object_id=article_id, country_id=str(country.object_id), state_id=str(issue.object_id), day=art, day_mm=str(get_mm_num(art)), sehri_time="4:3" + str(art) + " am", sehri_time_desc="Sehri", sehri_time_desc_mm_zawgyi=Rabbit.uni2zg("ဝါချည်ချိန်"), sehri_time_desc_mm_uni="ဝါချည်ချိန်", iftari_time="7:3" + str(art) + " pm", dua_mm_uni=Rabbit.zg2uni(str( daily_dua(art)["dua_mm"])), dua_mm_zawgyi=daily_dua(art)["dua_mm"], dua_ar=daily_dua(art)["dua_ar"], dua_en=daily_dua(art)["dua_en"], iftari_time_desc="Iftari", iftari_time_desc_mm_zawgyi=Rabbit.uni2zg("ဝါဖြေချိန်"), iftari_time_desc_mm_uni="ဝါဖြေချိန်") db_session.add(article) db_session.commit()