Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. import os
  2. import os.path
  3. import re
  4.  
  5. #WIP search up dictionary foler, count files, open files one by one.
  6.  
  7.  
  8.  
  9. def rawARPAbet():
  10.     directory = "dictionariesIPA/"
  11.    
  12.     all_dic = os.listdir(directory)
  13.  
  14.     print(all_dic)
  15.  
  16.     nah = 0
  17.     for f in all_dic:
  18.         nah += 1
  19.  
  20.     blankTXT = ''
  21.     kek = 0
  22.  
  23.     thisusedToWork=""
  24.     for f in all_dic:
  25.         dic_list = open(str(directory + all_dic[kek]), 'r', encoding='utf-8') #utf-16-le #utf-8
  26.   #      blankTXT += dic_list.read()
  27.    ##     convertToUpper = dic_list.read()
  28.         ###############print('HEYO')
  29.  
  30.         for line in dic_list:
  31.             if not line.strip(): continue
  32.  
  33.             #z = re.sub(r'(\/)', r'~', line)
  34.             #y = re.sub(r'(^.*?)(\s)(.*?)', r'\g<1>, \g<3>', z)
  35.             y = re.sub(r'(.*?)(\s)((\/).*?(\/))', r'\g<1>,  \g<3>', line)
  36.             x = y.split(',')
  37.             a=x[0]
  38.            
  39.             b=x[1]
  40.             a=a.upper()
  41.            
  42.             c=a+b
  43.            ################## print(c)
  44.            # c=re.sub(',', '   ')
  45.             blankTXT += c
  46.         blankTXT += "\n"        
  47.        
  48.         kek += 1
  49.      #   print(c)
  50.  
  51.     print(dic_list)
  52.     #print(blankTXT)
  53.        
  54.       #  if kek == nah:
  55.           #print()
  56.     ff = open('raw_IPA.txt', 'w', encoding='utf-8') #latin-1 #utf-8
  57.    
  58.     #convert small words to big words
  59.  
  60.    
  61.     ff.write(blankTXT)
  62.     ff.close()
  63.     dic_list.close()
  64.     print('raw_IPA.txt was successfuly created')
  65.    
  66. try:
  67.     print('Do you wish to create new "raw_IPA.txt"? \nY or N')
  68.     ######rawARPAbet()
  69.     con1 = input()
  70.     if (con1 == 'Y') or (con1 == 'y'):
  71.         print('creating raw_IPA.txt, please wait ~30 seconds for code to complete')
  72.         rawARPAbet()
  73.        
  74.     print("ART A complete, use PART B")
  75.  
  76. except:
  77.     print("""raw_ARPAbet.txt do not exist or cannot be created,
  78.          check if the folder 'dictionariesIPA' exist in same directory as
  79.          PY file and if it contains text files (encode UTF-8)""")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement