except: Date= str(grep("b'Date:",lines)).replace("b'",'') From= Decode(str(grep("b'From:",lines)).replace("b'",'')) To= Decode(str(grep("b'To:",lines)).replace("b'",'')) Subject= Decode(str(grep("b'Subject:",lines)).replace("b'",'')) print("",From,To,"\n",Subject,'\n\n',"this mail are purely composed by img or html",sep='\n') print('\n\n'+Date)
上傳以後,就翻車了。。 github和語雀問原作者,似乎一直沒有回 = =
except: Date= str(grep("b'Date:",lines)).replace("b'",'') From= Decode(str(grep("b'From:",lines)).replace("b'",'')) To= Decode(str(grep("b'To:",lines)).replace("b'",'')) Subject= Decode(str(grep("b'Subject:",lines)).replace("b'",'')) print("",From,To,"\n",Subject,'\n\n',"this mail are purely composed by img or html",sep='\n') print('\n\n'+Date)
BACK = requests.post(url, data= data, headers = header).json()['data'] print(Doc_Result[0])
這就, 成功啦~!
註: slug 必須是唯一的, 所以最好先檢查slug是否存在
defSlug_check(slug): try: requests.get(url+'/'+slug, headers = header).json()['status'] print('slug is unique') returnTrue except: print('Please check the slug. It may be occupied already.') returnFalse
defMDupDate(MD, Repos_ID, Doc_list): # read MD file F = open(MD,'r').read() Data_header = yaml.load(F.split('---')[1], Loader=yaml.FullLoader) # find the ID by slug/url if Data_header['url'] in [x['slug'] for x in Doc_list]: # 如果有單獨指定語雀標題: try: if Data_header['ytitle'] == "" : Title = Data_header['title'] else: Title = Data_header['ytitle'] except: Title = Data_header['title'] data = { #'id': 我不想指定, 還是隨機吧 'slug': Data_header['url'], # 這個還是最好要一個。 這個是網址 'title': Title, # 這就不用多說了吧。 'format': 'markdown', # 這必須markdown 呀 'body': MDbody_clean(F), 'status': "1"# 0 是草稿, 直接發佈把 } Doc_ID = [x['id'] for x in Doc_list][[x['slug'] for x in Doc_list].index(Data_header['url'])] header = {"X-Auth-Token": Identity['Token']} url = 'https://www.yuque.com/api/v2/repos/'+str(Repos_ID)+'/docs/'+ str(Doc_ID) Doc_Result = requests.put(url, data = data, headers = header).json()['data'] print(MD,"is updated") else: print(MD,' \033[91m', "這個文件還沒有被創建。我懶得寫一個新建接口了(防止太混亂)\n所以請覈對以後, 先上新建這個文件,再來更新把= =推薦用瓦雀直接創建", '\033[0m')
defCateg(Category): try: List = open(Category,'r').read().replace(" ",'').split("](") Cate_list = [A.split(")")[0] for A in List][1:] return"導入成功", Cate_list except: return"導入失敗", []
for MD in INPUT: run(MD) ''' if __name__ == "__main__": with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: executor.map(run, INPUT) '''