Example #1
0
def main():
    load_dotenv()

    req_data = request.get_json()
    items = req_data['groceries']
    user_geo_coord = list(req_data['location'].values())

    store_infos = get_locations(user_geo_coord)
    if len(store_infos) == 0:
        return {'err': 'No stores within max distance'}

    store_infos = get_address_and_distances(store_infos, user_geo_coord)
    if len(store_infos) == 0:
        return {
            'err': 'No stores within max distance'
        }  # Removes stores at unnamed addresses
    store_infos = store_infos[:
                              6]  # places cap on number of stores to find busyness of (API costs money)

    store_infos = get_busyness(store_infos)
    if len(store_infos) == 0:
        return {'err': 'Stores in the area have all closed down'}
    store_infos = store_infos[:
                              4]  # places cap on number of stores to execute item_find functionality on

    # execute item_finder functionality

    cost_sorted_stores = get_cost(store_infos)
    return {'cost_sorted_stores': cost_sorted_stores}
Example #2
0
def differences():
    locations = dict((key, value) for key, value in get_locations() if key)
    labels = normalized_labels_dict()
    location_prefixes = set(locations.keys())
    label_prefixes = set(labels.keys())
    print 'missing location data:'
    for label in sorted(label_prefixes.difference(location_prefixes)):
        print '    %s' % label
    print 'missing normalized labels:'
    for label in sorted(location_prefixes.difference(label_prefixes)):
        print '    %s' % label
Example #3
0
def handle_reset_locations(message):
    locations = get_locations(message.chat.id)

    if not locations:
        bot.send_message(
            message.chat.id,
            text='Nothing to delete. Feel free to /add new location!')
        return

    delete_locations(message.chat.id)
    bot.send_message(message.chat.id,
                     text="Done. All your locations were removed.")
Example #4
0
def handle_list_locations(message):
    locations = get_locations(message.chat.id)

    if not locations:
        bot.send_message(
            message.chat.id,
            text='Nothing to show. Feel free to /add new location!')
        return

    last_ten = [
        '{}. {}'.format(n + 1, v) for n, v in enumerate(
            loc.get('title') for loc in locations[-10:])
    ]
    message_to_user = '******'.join(
        ['Here is the list of your latest saved locations:', *last_ten])
    bot.send_message(message.chat.id, text=message_to_user)
Example #5
0
def genamh(filename):
    template = get_template()
    records = get_records(filename)
    locations = get_locations()

    for record in records:
        artwork = Artwork(record, locations)

        if not artwork.is_valid():
            continue

        artwork.process()
        data = artwork.get_data()

        if "nodata" not in sys.argv:
            data["jsondata"] = json.dumps(data)
            data["xmldata"] = escape(etree.tostring(record))

        html = template.render(data).strip().encode('utf-8')
        yield (html, data)
Example #6
0
def genamh(filename):
    template = get_template()
    records = get_records(filename)
    locations = get_locations()

    for record in records:
        artwork = Artwork(record, locations)

        if not artwork.is_valid():
            continue

        artwork.process()
        data = artwork.get_data()

        if "nodata" not in sys.argv:
            data["jsondata"] = json.dumps(data)
            data["xmldata"] = escape(etree.tostring(record))

        html = template.render(data).strip().encode('utf-8')
        yield (html, data)
    us_states_counties_ids = get_us_counties('lists/us_counties.tsv')
    # write the states counties ids dictionary to a text file
    json.dump(us_states_counties_ids, open("lists/us_states_counties_ids.json",'w'), sort_keys=True)

else :
    with open("lists/us_states_counties_ids.json") as json_file:
        us_states_counties_ids = json.load(json_file)

print '------------------\n'
print '------------------\n'
print us_states_counties_ids

create_locations = raw_input("Run get_locations and set_counties, y or n? ").rstrip()
if create_locations == 'y' :
    # locations is a dictionary of state dicts of city dictionaries
    locations = get_locations('lists/2014.txt')
    # get the county for the city, state and add it to the city dictionary
    set_counties(locations)
    # write the locations dictionary to a text file
    json.dump(locations, open("lists/locations.json",'w'), sort_keys=True)

else :
    with open("lists/locations.json") as json_file:
        locations = json.load(json_file)

raw_input('gotcha, here we go...')

print '------------------'
print '------------------\n'
print locations
raw_input('printed locations...')
Example #8
0
import os
import subprocess
import datetime
import re
from sendgrid import SendGridAPIClient  #sendgrid will need to be imported (run 'py -m pip install sendgrid' in new terminal window)
from sendgrid.helpers.mail import Mail
from tabulate import tabulate  #tabulate will need to be imported (run 'py -m pip install tabulate' in command prompt)

# Files
import settings
import locations
from locations import get_locations
from settings import *

not_active_endings = []
locations = get_locations()


def check_ping(ending):
    host = settings.IP_PRE + ending
    response = subprocess.Popen(
        ['ping', '-n', '4', host],
        stdout=subprocess.PIPE).communicate()[0].decode('UTF-8')
    response = response.replace('\n', '')
    loss = re.findall(r'\(.*(?= loss)', response)[0]
    loss = loss[1:]
    print(host + " --> Active (" + loss +
          " loss)") if loss == "0%" else print(host + " --> Not Active (" +
                                               loss + " loss)")
    if loss != "0%":
        not_active_endings.append(ending)
Example #9
0
 def _load_locations(self):
     self._locations = collections.defaultdict(int)
     for location in locations.get_locations():
         self._add_location(location)
     self._max_frequency = max(self._locations.values())
Example #10
0
 def _add_peers_from_log(self):
     for location in locations.get_locations():
         self._add_location(location)
Example #11
0
# DEBUG

# place names that don't
#  have a row in names.tsv
#  have articles on TolkienGateway (links.tsv)
#  have articles on EncyclopediaArda (links.tsv)

# canonical names that don't
#  have a row in locations.tsv
#  have a label in latin letters
#  have a label in the tengwar
#  have a region in regions.svg

from locations import locations as get_locations, CANONICAL, SINDARIN, ROMAN, OTHER

locations = get_locations()
from regions import regions2 as get_regions

regions = get_regions()
from links import links as get_links

links = get_links()
from names import names as get_names

names = get_names()
from labels import abnormal_labels as get_abnormal_labels, normalized_labels as get_normalized_labels

normalized_labels = [label for name, label in get_normalized_labels()]
abnormal_labels = [label for name, label in get_abnormal_labels()]
postpone_canonical_names = set(name.strip() for name in open("postpone.txt"))