Esempio n. 1
0
def export_ical():
    user_prefs = common.UserPreferences(1)

    if request.method == "GET":
        download = request.args.get("download")

        # The download argument indicates user clicked the download button
        if download:
            return send_file(download, as_attachment=True)

        # This is the default response the user should get upon first loading the Export page
        else:
            return render_template("export.html")

    elif request.method == "POST":
        source = request.form.get("source")
        start_date = request.form.get("start-date")
        end_date = request.form.get("end-date")

        if start_date and end_date:
            events = common.get_events_for_date_range(start_date, end_date, user_prefs, sources=[source])
            output_path = common.export_ical(events)

            return render_template("export.html", count=len(events), link=output_path, start=start_date, end=end_date)

        else:
            return render_template("export.html", message="You need to select a date range.")
Esempio n. 2
0
def viewer(year, month):

    user_prefs = common.UserPreferences(1)

    first_of_month = datetime.date(int(year), int(month), 1)

    month_of_events = common.get_one_month_of_events(int(year), int(month), preferences=user_prefs)
    output_calendar = twitter.calendar_grid(first_of_month, tweets=month_of_events)

    # After setting up the calendar, reverse the order if user preferences is set.
    if user_prefs.reverse_order == 1:
        month_of_events = twitter.reverse_events(month_of_events)

    # Quickly get next/previous months
    next_dt = datetime.date(first_of_month.year, first_of_month.month, 28) + datetime.timedelta(7, 0)
    next_dt = datetime.date(next_dt.year, next_dt.month, 1)
    prev_dt = datetime.date(first_of_month.year, first_of_month.month, 1) - datetime.timedelta(1, 0)

    navigation = {"previous": prev_dt.strftime("%Y/%m"),
                  "next": next_dt.strftime("%Y/%m")}

    cal_header = {"month": first_of_month.strftime("%B"),
                  "year": first_of_month.strftime("%Y")}

    pickers = twitter.build_date_pickers()

    date_values = {"year": year,
                   "month": month}

    return render_template("viewer.html", month=month_of_events, calendar=output_calendar,
                           header=cal_header, nav=navigation, pickers=pickers, date_values=date_values,
                           prefs=user_prefs)
Esempio n. 3
0
def user_settings():
    user_prefs = common.UserPreferences(1)

    if request.method == "GET":
        return render_template("settings.html", timezones=pytz.all_timezones, user_prefs=user_prefs)

    elif request.method == "POST":
        reverse_order = 1 if request.form.get('reverse_order') else 0
        print(f" reverse order is {reverse_order}")
        user_prefs.update(timezone=request.form.get('timezone'), reverse_order=reverse_order)
        print(f"Timezone is {request.form['timezone']}, saved successfully")
        save_message = "Changes saved successfully"

        return render_template("settings.html", timezones=pytz.all_timezones, user_prefs=user_prefs, msg=save_message)
Esempio n. 4
0
def event_filter_viewer():

    user_id = 1

    preferences = common.UserPreferences(user_id)

    filter_prefs = dict()

    event_types = ["twitter", "fitbit-sleep", "foursquare"]

    for event_type in event_types:
        filter_prefs[f"show_{event_type}"] = 1 if request.form.get(f"show_{event_type}") else 0

    preferences.save_filters(**filter_prefs)

    return redirect(url_for(request.form.get("dest"), year=request.form.get("year"), month=request.form.get("month"),
                            term=request.form.get("search")))
Esempio n. 5
0
def search():
    if request.method == "GET":
        user_prefs = common.UserPreferences(1)

        if request.args.get("term"):
            search_term = request.args.get("term")
            print(f"Searching for tweets containing '{search_term}'")
            # This is clumsy and won't scale... this twitter function should be moved to common and made scalable
            tweets = twitter.search_for_term(search_term, user_prefs)
            tweets = common.events_in_local_time(tweets, user_prefs, True)
            tweets = common.convert_dict_to_event_objs(tweets)

            # After setting up the calendar, reverse the order if user preferences is set.
            if user_prefs.reverse_order == 1:
                tweets = twitter.reverse_events(tweets)

            return render_template("search.html", events=tweets, default=search_term, count=len(tweets),
                                   prefs=user_prefs)

        else:
            return render_template("search.html", prefs=user_prefs)
    def test_foursquare_add_to_db(self):
        all_checkins = f.foursquareImporter('../data/fsq_test/')

        my_user = c.UserPreferences(1)
        all_checkins.add_to_database(my_user)
def process_from_file(file_path):
    current_user = common.UserPreferences(1)
    process_dir = common.unpack_and_store_files(file_path, "output")
    checkin_import = foursquareImporter(process_dir)
    checkin_import.add_to_database(current_user)
    common.cleanup(process_dir)
Esempio n. 8
0
def process_from_file(file_path):
    current_user = common.UserPreferences(1)
    process_dir = common.unpack_and_store_files(file_path, "output")
    sleep_import = FitbitSleepImporter(process_dir)
    sleep_import.add_to_database(current_user)
    common.cleanup(process_dir)
Esempio n. 9
0
            local_datetime.replace(tzinfo=None), timezone=new_timezone)
        self.timezone = new_timezone
        # store that in the db
        eventdb.update_fitbit_sleep_timezone(self.sleep_id,
                                             self.datetime.date(),
                                             self.datetime.time(),
                                             self.timezone)


def process_from_file(file_path):
    current_user = common.UserPreferences(1)
    process_dir = common.unpack_and_store_files(file_path, "output")
    sleep_import = FitbitSleepImporter(process_dir)
    sleep_import.add_to_database(current_user)
    common.cleanup(process_dir)


if __name__ == "__main__":
    all_data = FitbitSleepImporter("data/Fitbit Sleep")
    print(all_data.get_item(106))
    my_user = common.UserPreferences(1)

    maxlog = 0
    for item in all_data.json_list:
        maxlog = item["logId"] if item["logId"] > maxlog else maxlog

    all_data.add_to_database(my_user)
    print(len(all_data))

    print(maxlog)