def main(launch: bool = True): try: import settings enable_sentry: bool = settings.get('sentry_level') != 'Never' except Exception: enable_sentry = True # will almost certainly crash later anyway if this happens try: if enable_sentry: # set up Sentry (https://sentry.io/) sentry_sdk.init(dsn=utils.get_api_key('sentry'), release=VERSION, attach_stacktrace=True, max_breadcrumbs=50, debug=DEBUG, environment="Debug build" if DEBUG else "Release", request_bodies='small') with sentry_sdk.configure_scope() as scope: user_pc_name: str = socket.gethostname() try: user_identifier: str = getpass.getuser() except ModuleNotFoundError: user_identifier = user_pc_name scope.user = {'username': f'{user_pc_name}_{user_identifier}'} import main if launch: main.launch() except SystemExit: raise except Exception: handle_crash()
def send_rpc_activity(self): try: if not self.client_connected: # connects to Discord self.log.debug("Connecting to Discord IPC...") self.rpc_client = ipc.DiscordIPC(utils.get_api_key('discord2')) self.rpc_client.connect() self.log.debug("Connection successful") self.game_state.update_rpc = True self.rpc_client.update_activity(self.activity) self.log.info(f"Sent over RPC: {self.activity}") client_state: tuple = (self.rpc_client.client_id, self.rpc_client.connected, self.rpc_client.ipc_path, self.rpc_client.pid, self.rpc_client.platform, self.rpc_client.socket) self.log.debug(f"Client state: {client_state}") self.client_connected = True except Exception as client_connect_error: if str(client_connect_error) in ( "Can't send data to Discord via IPC.", "Can't connect to Discord Client."): # often happens when Discord is in the middle of starting up self.handle_rpc_error(str(client_connect_error)) else: raise
def put(self): args = self.reqparse.parse_args() session_tasks = settings.tasks[get_api_key()] for task in session_tasks: for key, value in args.items(): if value is not None: task[key] = value return {'tasks': [marshal(task, fields.tasks) for task in session_tasks]}
def __init__(self, api_user=None, api_key=None, api_url=None): api_user = api_user or utils.get_api_user() api_key = api_key or utils.get_api_key() api_url = api_url or utils.get_api_url() self.client = client.OpenStackClient(api_user, api_key, api_url) self.flavors = flavors.FlavorManager(self) self.images = images.ImageManager(self) self.servers = servers.ServerManager(self)
def post(self): self.reqparse.add_argument('text', type=str, required=True, location='json') args = self.reqparse.parse_args() session_tasks = settings.tasks[get_api_key()] task = { 'id': len(session_tasks) + 1, 'text': args['text'], 'complete': False } session_tasks.append(task) return {'task': marshal(task, fields.tasks)}, 201 # Return new task
def put(self, id): session_tasks = settings.tasks[get_api_key()] task = [task for task in session_tasks if task['id'] == id] if len(task) == 0: abort(404) task = task[0] args = self.reqparse.parse_args() for k, v in args.items(): if v is not None: task[k] = v return {'task': marshal(task, fields.tasks)} # Return updated task
#!/usr/bin/env python2 # -- coding: utf-8 -- import requests import unicodecsv from utils import get_api_key token = get_api_key() url = 'https://www.muckrock.com/api_v1/' headers = {'Authorization': 'Token %s' % token, 'content-type': 'application/json'} next_ = url + 'communication' fields = ( "id", "ffile", "title", "date", "source", "description", "access", "doc_id", "pages" ) page = 1 csv_file = open('doccloudfiles.csv', 'w') csv_file.seek(0) csv_writer = unicodecsv.writer(csv_file) csv_writer.writerow(fields)
#!/usr/bin/env python2 # -- coding: utf-8 -- import requests import unicodecsv from utils import get_api_key token = get_api_key() url = 'https://www.muckrock.com/api_v1/' headers = { 'Authorization': 'Token %s' % token, 'content-type': 'application/json' } next_ = url + 'jurisdiction' fields = ("id", "name", "slug", "full_name", "level", "parent", "days", "absolute_url", "average_response_time", "fee_rate", "success_rate") page = 1 csv_file = open('jurisdiction_stats.csv', 'w') csv_file.seek(0) csv_writer = unicodecsv.writer(csv_file) csv_writer.writerow(fields) while next_ is not None: r = requests.get(next_, headers=headers) try: json = r.json() next_ = json['next']
""" Wrap up function to calcualte crawl """ self.getLatLngs() self.findCentre() self.calcRadius() self.getNearbyPlaces() self.calcDistances() self.getMinRoute() if __name__ == '__main__': start_string = 'The Anchor, 34 Park St, Southwark, London SE1 9EF' end_string = 'Southwark Brewing Company' n_places = 2 radius_factor = 1 keywords = ['bar', 'beer'] mode = "bicycling" api_key = get_api_key() bc = BeerCrawler(start_string=start_string, end_string=end_string, n_places=n_places, radius_factor=radius_factor, keywords=keywords, mode=mode, api_key=api_key) bc.calculateTopXCrawl() print bc.directions
#!/usr/bin/env python2 # -- coding: utf-8 -- import requests import json import utils url = utils.API_URL token = utils.get_api_key() headers = utils.get_headers(token) EXISTING_PKS = [] # If you've already filed with a given agency, or otherwise want to exclude it, include its ID here. AGENCY_PKS = [248] # Agency ID 248 is a test agency under federal jurisdiction 10. This ID is subject to change, and will deduct requests from your account. Contact [email protected] and we'll add them back. AGENCY_PKS = filter(lambda x: x not in EXISTING_PKS, AGENCY_PKS) DOCS = """ A copy of your reports that are: Annual Monthly Bimonthly """ TITLE = 'Records Request' # Customize here for your project for agency_pk in AGENCY_PKS: # get the jurisdiction r = requests.get(url + 'agency/{}/'.format(agency_pk), headers=headers) jurisdiction_pk = r.json()['jurisdiction'] print 'Filing for {}...'.format(r.json()['name'])
type=str, required=True, choices=["red", "black", "yellow"], help="ePaper display colour") args = parser.parse_args() # Set up the display colour = args.colour inky_display = InkyPHAT(colour) inky_display.set_border(inky_display.BLACK) # Details to customise your weather display DATAPOINT_ID = '353883' DATAPOINT_KEY = get_api_key() USE_LOCAL_TEMP = True USE_BATTERY = True # Python 2 vs 3 breaking changes def encode(qs): val = "" try: val = urllib.urlencode(qs).replace("+", "%20") except AttributeError: val = urllib.parse.urlencode(qs).replace("+", "%20") return val # Query the MetOffice weather API
def test_get_api_key(self): self.assertEqual(len(utils.get_api_key('discord')), 18) self.assertEqual(len(utils.get_api_key('discord2')), 18) self.assertEqual(len(utils.get_api_key('sentry')), 91)
def get(self): session_tasks = settings.tasks[get_api_key()] return {'tasks': [marshal(task, fields.tasks) for task in session_tasks]}
) ###get info lists place_ids = map(lambda x: x['place_id'],nearby['results']) place_info = map(lambda x: gmaps.place(x),place_ids) place_names = map(lambda x: x['result']['formatted_address'],place_info) #calculate distances from combinations #distances = calculate_distances(gmaps,start,end,place_names,n_places) #get min distance for waypoints #min_dist = min([x[1] for x in distances]) #print min_dist #final_waypoints = [x for x in distances if x[1]==min_dist] #print final_waypoints #print min_dist #final_directions = gmaps.directions( #start, #end, #mode=mode, #waypoints=final_waypoints[0][0] #) #print final_directions if __name__ == '__main__': api_key = get_api_key() main(api_key)