#!/usr/bin/python3 import sys import os import requests import json from time import sleep from random import randint, uniform from credentials import getToken from help import help from check import check, set_check, get_loc_status if __name__ == "__main__": token = getToken() if len(sys.argv) > 1: command = sys.argv[1] if (command in set(["-h", "--help"])): help() elif (command == "run"): dry = -1 if len(sys.argv) > 2: flag = sys.argv[2] if len(flag) > 2 and flag[:2] == "-d": try: dry = int(flag[2:]) except: print("Not a valid value for `n`!") if dry == -1: os.system("echo 'Replace this with git push code'") os.system("echo 'Replace this with checker API code'") elif (command == "status"):
class Router: fromLoc = 0 toLoc = 0 names = [] token = getToken()['access_token'] def __init__(self, fromLoc, toLoc): self.fromLoc = fromLoc self.toLoc = toLoc def getAverageCovid(self, locationObjects): locationObjects = self.names covidSum = 0 for location in locationObjects: if location['P14_100k_T'] != 'Less than 5 cases': covidSum += float(location['P14_100k_T']) return covidSum / len(locationObjects) def getMaxCovid(self, locationObjects): locationObjects = self.names covidMax = 0 maxLocation = 0 for location in locationObjects: if location['P14_100k_T'] != 'Less than 5 cases': if float(location['P14_100k_T']) > covidMax: covidMax = float(location['P14_100k_T']) maxLocation = location return maxLocation def getRoutes(self): routes = [] response = self.routeApi() locationObjects = response['response']['route'][0]['leg'][0][ 'maneuver'] self.names = getLocNames(locationObjects) locationJson = self.locationsToJsonRoute(locationObjects) routes.append(locationJson) average1 = self.getAverageCovid(locationObjects) bboxstr = self.getBboxString(locationObjects) response1 = self.routeApi(bboxstr=bboxstr) secondRoute = response1['response']['route'][0]['leg'][0]['maneuver'] self.names = getLocNames(secondRoute) time.sleep(2) secondjson = self.locationsToJsonRoute(secondRoute) routes.append(secondjson) average2 = self.getAverageCovid(secondRoute) return routes def locationsToJsonRoute(self, locations): latlons = [] returnObject = [] for location in locations: latlons.append({ 'lat': location['lat'], 'lon': location['lon'], 'id': location['id'] }) returnObject.append({'LocNames': self.names, 'latlons': latlons}) return json.dumps(returnObject) def routeApi(self, *args, **kwargs): payload = { 'Content-Type': 'application/json', 'waypoint0': 'geo!' + str(self.fromLoc['lat']) + ',' + str(self.fromLoc['lng']), 'waypoint1': 'geo!' + str(self.toLoc['lat']) + ',' + str(self.toLoc['lng']), 'mode': 'fastest;car;traffic:disabled', 'avoidareas': '', 'return': 'polyline' } if isinstance(kwargs.get('bboxstr', None), str): payload['avoidareas'] = kwargs.get('bboxstr', None) securityparams = {'grant_type': 'client_credentials'} r = requests.get( 'https://route.ls.hereapi.com/routing/7.2/calculateroute.json', headers={'Authorization': 'Bearer {}'.format(self.token)}, params=payload) r = r.json() locations = r['response']['route'][0]['leg'][0]['maneuver'] for location in locations: location['lat'] = location['position']['latitude'] location['lon'] = location['position']['longitude'] del location['position'] r['response']['route'][0]['leg'][0]['maneuver'] = locations return r def getBboxString(self, locationObjects): avoidareas = '' maxCovid = self.getMaxCovid(locationObjects[1:len(locationObjects) - 1]) boundingBox = getBoudingBox(maxCovid['ENGLISH']) avoidareas += str(boundingBox[3]) + ',' + str( boundingBox[2]) + ';' + str(boundingBox[1]) + ',' + str( boundingBox[0]) return avoidareas
from __future__ import unicode_literals import asyncio import discord import youtube_dl import credentials from discord.ext import tasks, commands import datetime import time youtube_dl.utils.bug_reports_message = lambda: '' token = credentials.getToken() ytdl_options = { 'format': 'bestaudio/best', 'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s', 'restrictfilenames': True, 'noplaylist': True, 'nocheckcertificate': True, 'ignoreerrors': False, 'logtostderr': False, 'quiet': True, 'no_warnings': True, 'default_search': 'auto', # bind to ipv4 since ipv6 addresses cause issues sometimes 'source_address': '0.0.0.0', 'cachedir': False } ffmpeg_options = { 'options': '-vn'
#I need to fix this. plays = [ "with himself", "with your mind", "with gravity", "dead", "with fire" ] playing = randSample(plays, 1)[0] while True: await client.change_presence(game=discord.Game(name=playing)) for _ in range(3600): await asyncio.sleep(1) if list(gmtime())[3] % 2: await client.change_presence(game=discord.Game(name=playing)) @client.event async def call_admin(channel, reason=None): text = "Generals @admin , another settlement needs your help. #{0} {1}".format( channel.name, reason) #434578647110778882 is the channel id for LearnJapanese #secret-scheming. await client.send_message(client.get_channel("434578647110778882"), text) #await client.send_message(client.get_channel("434287964269445122"), text) client.run(credentials.getToken())