def get_by_hash_tag(hash_tag, since="2014-07-12"): # build directory for hashtag data if it is not already there dir_path = os.path.join(os.getcwd(), "#{}".format(hash_tag)) if not directory_exists(dir_path): os.mkdir(dir_path) print(dir_path) clean_folder(dir_path) api = get_api() raw_query = "q=%23{}&count=100&include_entities=true&result_type=recent&since={}".format( hash_tag, since) results = api.GetSearch(raw_query=raw_query, return_json=True) i = 1 filepath = os.path.join(dir_path, str(i) + "_" + "out.json") print(json.dumps(results, indent=2)) write_json(filepath, json.dumps(results, indent=2)) while True: i += 1 # time.sleep(30) if results['search_metadata'] and 'next_results' in results[ 'search_metadata']: results = api.GetSearch( raw_query=results['search_metadata']['next_results'][1:], return_json=True) print(json.dumps(results, indent=2)) filepath = os.path.join(dir_path, str(i) + "_" + "out.json") write_json(filepath, json.dumps(results, indent=2)) else: break
def main(): args = parser() torrentfiles = list() magnets = dict() source = args.input if source.endswith('/') or source.endswith('.'): for tfile in listdir(source): if tfile.endswith('.torrent'): torrentfiles.append(tfile) else: torrentfiles.append(source) for torrent in torrentfiles: magnets[torrent] = get_magnet(torrent) output = args.output if output is None: for torrent in magnets: print('%s\t%s' %(torrent, magnets[torrent])) else: if output.endswith('.json'): write_json(output, magnets) elif output.endswith('.html'): write_file(output, get_html(magnets)) else: print('error: output was not correct. use file.{json,html} as parameter')
def remove_all_urls(): """ Remove all available urls in the url json file :return: ApiResponse """ payload = {"urls": []} helpers.write_json(payload, url_config_path) return ApiResponse(data="all urls removed successfully")
def remove_url(url: str = Form(...)): """ Remove url from the url json file :param url: api url in the format: http://ip:port/ :return: ApiResponse """ try: payload = helpers.parse_json(url_config_path) except Exception as e: return ApiResponse(success=False, error=e) if url in payload['urls']: payload['urls'].remove(url) helpers.write_json(payload, url_config_path) return ApiResponse(data={"url removed successfully"}) else: return ApiResponse(success=False, error="url is not present in config file")
def single_episode(): # Play episode print("Play") num_iters, episode_reward, done = play() # Update policies print("Train") update_policies(models, gs) gs.reset() # Save episode data tracked_rewards.append(episode_reward) tracked_durations.append(num_iters) write_json(tracked_rewards, os.path.join(MODELS_FOLDER, "rewards.json")) write_json(tracked_durations, os.path.join(MODELS_FOLDER, "durations.json"))
def set_url(url: str = Form(...)): """ Add url to the url json file :param url: api url in the format: http://ip:port/ :return: ApiResponse """ try: payload = helpers.parse_json(url_config_path) response = helpers.check_api_availability(url) except Exception as e: return ApiResponse(success=False, error=e) if response.status_code == 200: if url not in payload['urls']: payload['urls'].append(url) helpers.write_json(payload, url_config_path) data = "url added successfully" else: data = "url already exist" return ApiResponse(data=data) else: return ApiResponse(success=False, error="url trying to add is not reachable")
def save(self): if not self._token: raise exceptions.TokenNotFound() helpers.write_json(settings.API_ACCESS_TOKEN, self._token_data)
def export_results(self): self.log(f'Exporting final match results to {self.outputfile}') write_json(self.outputfile, self.get_output_data()) return self.outputfile
#!/usr/bin/env python2.7 # -.- coding: utf-8 -.- from helpers import write_json, configfile settings = { 'mktorrent': 'mktorrent', 'comment': 'your mom', 'trackers': [ 'udp://tracker.openbittorrent.com:80/announce', 'udp://tracker.publicbt.com:80/announce', ], 'webseeds': [ 'http://webseed.example.com/', ], } if __name__ == '__main__': write_json(configfile, settings)