示例#1
0
def find_slots(zipcode: str):
    result = requests.get(BASE_URL + zipcode)
    data = result.json()

    cur_week = datetime.now().isocalendar()[1]

    data = data.get("_embedded").get("lanes")[3].get("_embedded").get(
        "items")[0].get("_embedded")
    total_slots = 0
    for day in data.get("deliveryDates"):
        date = datetime.strptime(day['date'], "%Y-%m-%d")
        if date.isocalendar()[1] == cur_week:
            r = 0
            for slot in day['deliveryTimeSlots']:
                if slot['state'] != "full":
                    r += 1
            total_slots += r

    if total_slots > 0:
        notify = Notify()
        if notify.config_file_exists:
            notify.read_config()
        else:
            print(notify.register())
            notify.write_config()
        print("[" + str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) +
              "] Notifying about " + str(total_slots) + " available slots")
        notify.send("AH Bezorg slots beschikbaar", "https://www.ah.nl")
示例#2
0
def check_for_tweets():
    twitter = Twitter(os.path.join(BASE_DIR, CONFIG_FILE))

    try:
        # Check which tweets have already been processed
        with open(os.path.join(BASE_DIR, "prev_id"), "r") as file:
            prev_id = int(file.read())
    except FileNotFoundError:
        # File 'prev_id' does not exist, set it as his most recent tweet
        tweets = twitter.get_tweets_from_user(PROJECT_SETTINGS['elonHandle'])
        prev_id = tweets[0].id

    # Load the keywords we are checking for
    with open(os.path.join(BASE_DIR, "keywords"), "r") as file:
        keys = file.read()
    keywords = keys.split("\n")

    # Load tweets
    tweets = twitter.get_tweets_from_user_since(PROJECT_SETTINGS['elonHandle'],
                                                prev_id)

    # Check the tweets for keywords
    found = set()
    max_id = prev_id
    for tweet in tweets:
        id = tweet.id
        txt = str(tweet.text).lower()
        for key in keywords:
            if key in txt:
                found.add(key)
        if id > max_id:
            max_id = id

    # Save our progress
    with open(os.path.join(BASE_DIR, "prev_id"), "w") as file:
        file.write(str(max_id))

    # Notify if necessary
    if len(found) > 0:
        msg = "Elon Tweeted about the following topics: '" + ", ".join(
            found) + "'"

        notify = Notify()
        if notify.config_file_exists:
            notify.read_config()
        else:
            print(notify.register())
            notify.write_config()

        print("[" + str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) +
              "] Sending notification: " + msg)

        notify.send(
            msg, "https://www.twitter.com/" + PROJECT_SETTINGS['elonHandle'])
        for f in tq:
            pass

spectra = []
for f in futures + redoFutures:
    try:
        spectra.append(f.result())
    except:
        spectra.append(None)

name = 'HerculesNrCube.pickle'
with open(name, 'wb') as f:
    pickle.dump(spectra, f)

notify = Notify()
notify.read_config()
notify.send('%s <%s> done!' % (__file__, socket.gethostname()))

# atmosHse = Atmosphere(ScaleType.Geometric, depthScale=atmosData['height'], temperature=atmosData['temp'], vlos=atmosData['vlos'], vturb=4000*np.ones_like(atmosData['height']))

# atmosHse.convert_scales(Ptop=atmosData['pgas'][0])
# atmosHse.quadrature(5)

# aSet = RadiativeSet([H_3_atom(), C_atom(), O_atom(), Si_atom(), Al_atom(), CaII_atom(), Fe_atom(), He_atom(), MgII_atom(), N_atom(), Na_atom(), S_atom()])
# aSet.set_active('Ca')
# spectHse = aSet.compute_wavelength_grid()
# eqPopsHse = aSet.iterate_lte_ne_eq_pops(mols, atmosHse)
# ctxHse = LwContext(atmosHse, spectHse, eqPopsHse, conserveCharge=False, initSol=InitialSolution.Lte)
# iterate_ctx(ctxHse, prd=False)
# eqPopsHse.update_lte_atoms_Hmin_pops(atmosHse)
# IwaveHse = ctxHse.compute_rays(wave, [1.0])