def create_vacancy_telegraph_page(vacancy: Vacancy, telegraph_account: Telegraph): title = vacancy.name parsed_description = vacancy.description.replace("\n", "<br>") html_content = ( f"<b>Категорія</b>: {vacancy.tag}<br>" f"<b>Досвід</b>: {vacancy.experience}<br>" f"<b>Зарплата</b>: {vacancy.salary}<br>" f"<b>Робочий день</b>: {vacancy.employment_type}<br>" f"<h3>Опис</h3>{parsed_description}<br>" ) author_name = telegraph_account.get_account_info()["author_name"] author_url = telegraph_account.get_account_info()["author_url"] try: response = telegraph_account.create_page( title=title, html_content=html_content, author_name=author_name, author_url=author_url, ) vacancy.telegraph_link_token = response["path"] vacancy.save() except Exception as e: print(e)
def test_flow(self): telegraph = Telegraph() response = telegraph.create_account( short_name='python telegraph', author_name='Python Telegraph API wrapper', author_url='https://github.com/python273/telegraph') self.assertTrue('access_token' in response) self.assertTrue('auth_url' in response) response = telegraph.get_account_info() self.assertEqual(response['short_name'], 'python telegraph') response = telegraph.edit_account_info( short_name='Python Telegraph Wrapper') self.assertEqual(response['short_name'], 'Python Telegraph Wrapper') response = telegraph.create_page('Python Telegraph API wrapper', html_content='<p>Hello, world!</p>') telegraph.edit_page(response['path'], 'Python Telegraph API Wrapper', html_content=POST_HTML_CONTENT) response = telegraph.get_views(response['path']) self.assertTrue('views' in response) response = telegraph.get_page_list() self.assertTrue(response['total_count'] > 0) response = telegraph.revoke_access_token() self.assertTrue('access_token' in response) self.assertTrue('auth_url' in response)
p = Pool() print("pool start...") for arg in sys.argv: if arg == sys.argv[0]: continue p.apply_async(main_up, args=(arg, )) p.close() p.join() print("upload final") input("waiting for input") else: inp = input("输入info获取信息,输入list获取所有的文章列表") if inp == "info": print( telegraph.get_account_info([ 'short_name', 'author_name', 'author_url', 'auth_url', 'page_count' ])) print(telegraph.get_access_token()) if inp == "list": offset = 0 while True: page_list = telegraph.get_page_list(offset, 10) print("共有{total}篇文章,目前显示的是{page_s}-{page_e}页".format( total=page_list['total_count'], page_s=offset + 1, page_e=offset + 10)) pages = page_list['pages'] for args in pages: for key, value in args.items(): print("{}:{}".format(key, value)) print("")