default=config.headless) parser.add_argument('--history', default=config.twitterhelpbot.history) parser.add_argument('--output_file', default=config.twitterhelpbot.output_file) parser.add_argument('--debug', action='store_true', default=config.debug) args = parser.parse_args() logger = utils.get_logger( logging.INFO if not args.debug else logging.DEBUG) logger.info("start") commands = ["香港直擊", "國際戰線", "外語新聞"] with browser_init("https://web.telegram.org/#/im?p=@TwitterHelpBot", executable_path=args.executable_path, profile_path=args.profile_path, headless=args.headless) as browser: browser.wait(By.CLASS_NAME, "im_dialog", args.wait) time.sleep(5) input = browser.find_element_by_class_name("composer_rich_textarea") urls = [] if args.continuation: for url in [ a.get_attribute('href') for a in browser.find_elements_by_xpath( "(//div[@class='im_message_text'])[last()]/a")[:-1] ]: urls.append( urllib.parse.unquote(re.search('url=(.+)', url).group(1))) else:
action='store_true', default=config.headless) parser.add_argument('--history', default=config.tweetall.history) parser.add_argument('--debug', action='store_true', default=config.debug) args = parser.parse_args() logger = utils.get_logger( logging.INFO if not args.debug else logging.DEBUG) logger.info('start') regex = re.compile(r"https://(?:www\.)?twitter\.com/.+\/status\/[^\s]+") urls = set() with browser_init(executable_path=args.executable_path, profile_path=args.profile_path, headless=args.headless) as browser: if os.path.exists(args.url_or_file): with open(args.url_or_file, newline="", encoding="utf-8") as f: for line in f: for url in regex.findall(line): urls.add(url) else: browser.get(args.url_or_file) time.sleep(5) for a in browser.find_elements_by_tag_name('a'): for url in regex.findall(a.get_attribute('href')): urls.add(url) utils.retweet_all(browser, urls, args.history)
sys.stdout.reconfigure(encoding='utf-8') r = re.compile(r"\/@([\d\.]+),([\d\.]+),([\d]+)z\/") def get_long_lat_zoom(driver, address): address = address.strip() elem = driver.find_element_by_id("searchboxinput") elem.clear() elem.send_keys(address) elem.send_keys(Keys.RETURN) current_address = driver.current_url matches = None while current_address == driver.current_url or matches is None or driver.current_url[-1] == '/': time.sleep(1) matches = r.search(driver.current_url) matches = r.search(driver.current_url) return address, matches.group(1), matches.group(2), matches.group(3) if __name__ == "__main__": parser = argparse.ArgumentParser(description='Find the GPS info from a list of addresses') parser.add_argument('places_file', nargs='?', default="places.txt") args = parser.parse_args() with browser_init("http://maps.google.com", private=True) as browser: with open(args.places_file, newline="", encoding="utf-8") as f: for line in f: address, long, lat, zoom = get_long_lat_zoom(browser, line) print(f"{address}\t{long}\t{lat}\t{zoom}") time.sleep(1)