Beispiel #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")
Beispiel #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'])
Beispiel #3
0
from collections import Counter
from notify_run import Notify
import os
import time
import dropbox
import json
dropboxkey = ""
notify = Notify()
notifyendpoint = ""
notify.endpoint = notifyendpoint
notify.write_config()

from flask import Flask, request
maindictionary = {}
dbx = dropbox.Dropbox(dropboxkey)
dbx.files_download_to_file("bannedpixel.txt", "/bannedpixel.txt")
dbx.files_download_to_file("logpixel.txt", "/logpixel.txt")
dbx.files_download_to_file("dictionary.txt", "/dictionary.txt")

app = Flask(__name__)


@app.route("/pixel")
def home():
    maindictionary = json.load(open("dictionary.txt"))
    if (request.args.get("id")) in open("bannedpixel.txt").read():
        pass
    elif open("logpixel.txt").read().count(request.args.get("id")) == 0:
        with open("logpixel.txt", "a+") as f:
            f.writelines(request.args.get("id") + "\n")
        dbx = dropbox.Dropbox("")
Beispiel #4
0
def notify_mikkel():
    notify = Notify(api_server='https://notify.run/api/', endpoint="https://notify.run/tgxHEXy7AVp1Ea6Q")
    notify.write_config()
    notify.send("Uddannelse fundet test")
    global notified
    notified = True