def test_register_updates_user_if_user_is_registered( users: Users, test_users: Sequence[User], test_registrants: Sequence[Registrant], sheets: Sheets, registrations: Registrations, ): """register_user() should update the user but not re-register if user is already registered""" existing_registrant = test_registrants[0] for user in test_users: if user.email == existing_registrant.user_email: updated_user = user break updated_user.first_name = "updated_first" updated_user.last_name = "updated_last" updated_user.organization = "updated_org" updated_user.tshirt_size = "update_size" sheets.register_user( RegisterUser( hackathon="newhackathon_2019", first_name=updated_user.first_name, last_name=updated_user.last_name, email=updated_user.email, organization=updated_user.organization, role=updated_user.role, tshirt_size=updated_user.tshirt_size, )) retrieved_user = users.find(existing_registrant.user_email) assert retrieved_user == updated_user
def parse_email(): payload = request.json body = payload["body"] subject = payload["subject"] sheet = Sheets() print(repr(body)) if "You paid" in subject: description = extract("(?<=\) \\n \\n)(.*)(?= \\n \ T)", body) amount = extract("(?<=\- \$)(.*)(?= \\n \\n L)", body) category = assign_cat_venmo(description) method = "Vemno" sheet.add_expense(amount, description, category, method) elif "charge request" in subject: description = extract("(?<=\-5\) \\n \\n)(.*)(?= \\n T)", body) amount = extract("(?<=\- \$)(.*)(?= \\n \\n L)", body) category = assign_cat_venmo(description) method = "Vemno" sheet.add_expense(amount, description, category, method) elif "Your Single Transaction Alert from Chase" in subject: description = extract("(?<= at )(.*)(?= has been authorized)", body) amount = extract("(?<=charge\ of\ \(\$USD\) )(.*)(?=\ at)", body) category = assign_cat_card(description) method = "Chase" sheet.add_expense(amount, description, category, method) return jsonify({"success": "true"})
def test_register_user_registers_when_user_exists( test_users: Sequence[User], sheets: Sheets, users: Users, registrations: Registrations, ): """register_user() should register a user by adding them to the Registrations sheet if user already exists in the Users sheet but not in the Registrations sheet. """ existing_user = test_users[0] registered_user = sheets.register_user( RegisterUser( hackathon="newhackathon_2019", first_name=existing_user.first_name, last_name=existing_user.last_name, email=existing_user.email, organization=existing_user.organization, role=existing_user.role, tshirt_size=existing_user.tshirt_size, )) assert registered_user == existing_user all_users = sorted(users.rows(), key=lambda a: a.id) test_users = sorted(test_users, key=lambda t: t.id) assert all_users == test_users all_registrants = registrations.rows() last_registrant = all_registrants[-1] assert last_registrant.user_email == existing_user.email assert last_registrant.hackathon_name == "newhackathon_2019" assert last_registrant.date_registered assert (last_registrant.date_registered.date() == datetime.datetime.now( tz=datetime.timezone.utc).date()) assert last_registrant.attended is None
def __init__(self): self.database = Db() self.googlesheet = Sheets() self.workstation = WorkStation() self.workstation.set_manager(self) self.raven = Raven(raven_token, raven_json_path) self.raven.set_manager(self) self.emptydf = pd.DataFrame(columns=Xone.attrs) self.pending: DictOfXones = OrderedDict( self.spawn_multiple(self.database.pending)) self.open: DictOfXones = OrderedDict( self.spawn_multiple(self.database.open)) self.closed: DictOfXones = OrderedDict( self.spawn_multiple(self.database.closed)) self.all = dict(pending=self.pending, open=self.open, closed=self.closed) self.alive = {**self.pending, **self.open} self.event = Event() self.updater = Thread(target=self.update, daemon=True) self.updater.start() self.event.set()
def test_register_user_registers(sheets: Sheets, users: Users, registrations: Registrations, test_data): """register_user() should register new users by adding them to the Users sheet and to the Registrations sheet """ new_user = sheets.register_user( RegisterUser( hackathon="sanfrancisco_2019", first_name="New", last_name="Registrant", email="*****@*****.**", organization="New Company", role="Data person", tshirt_size="M", )) all_users = users.rows() last_inserted_user = all_users[-1] assert new_user == last_inserted_user all_registrants = registrations.rows() last_registrant = all_registrants[-1] assert last_registrant.user_email == new_user.email assert last_registrant.hackathon_name == "sanfrancisco_2019" assert last_registrant.date_registered assert (last_registrant.date_registered.date() == datetime.datetime.now( tz=datetime.timezone.utc).date()) assert last_registrant.attended is None
def __init__(self, cut_space=1 * mm, card_width=2.5 * inch, card_height=3.5 * inch, **kwargs): # Call Super Sheets.__init__(self, **kwargs) # Copy values self.cut_space = cut_space self.indent_space = 0.0 self.card_width = card_width self.card_height = card_height #Perform initial shift to make sure we're at the right spot...not robust. self.shiftPos(self.card_height)
def processExpense(): payload = request.json parsedReq = parsePayload(payload) if not parsedReq: return jsonify({ "success": "false", "msg": "illegal request body" }) sheet = Sheets() sheet.addExpense(parsedReq["amount"], parsedReq["description"], parsedReq["category"], parsedReq["method"]) return jsonify({ "success": "true" })
def main(): manager = Sheets('client_secret.json') email = GmailHandler(config.USERNAME, config.PASSWORD) movie_data = email.retrieve_email() if movie_data: manager.reformat_data('temp', movie_data) manager.add_new_movies('temp.json') if email.alert_email(): os.remove('temp.json') print('Complete')
def parse_email(): payload = request.json body = payload["body"] subject = payload["subject"] sheet = Sheets() print(repr(body)) if "Your purchase was successful" in subject: description = extract("(?<= at )(.*)(?= was successful)", body) amount = extract("(?<=Your purchase of )(.*)(?=\ at)", body) category = assign_cat_card(description) method = "BRIM" sheet.add_expense(description, amount, category, method) elif "BMO Credit Card Alert" in subject: description = extract("(?<= at )(.*)(?= was approved)", body) amount = extract("(?<= in the amount of )(.*)(?= at)", body) category = assign_cat_card(description) method = "BMO" sheet.add_expense(description, amount, category, method) return jsonify({"success": "true"})
from __future__ import (absolute_import, division, print_function, unicode_literals) from collections import OrderedDict import backtrader as bt from Grid.mysizer import MySizer from Grid.xone import * from nifty50list import NIFTY50LIST from sheets import Sheets googlesheet = Sheets() class Grid(bt.Strategy): params = (('gsheet', googlesheet), ('pending', googlesheet.pxones), ('open', googlesheet.oxones), ('closed', googlesheet.cxones), ('maxpos', 5)) def __init__(self): self.order = None self.orders = {data: None for data in self.datas} self.pxones = OrderedDict( {d['symbol']: Xone(**d) for d in self.p.pending}) self.oxones = OrderedDict( {d['symbol']: Xone(**d) for d in self.p.open}) self.cxones = OrderedDict( {d['symbol']: Xone(**d)
def test_gets_all_hackathons(sheets: Sheets, test_data): """get_hackathons() should return all active hackathons.""" hackathons = sheets.get_hackathons() assert isinstance(hackathons, list) assert len(hackathons) > 0
def instantiate_sheets(spreadsheet, cred_file): """Creates and returns an instance of Sheets""" return Sheets(spreadsheet_id=spreadsheet["spreadsheetId"], cred_file=cred_file)
import json import logging import time import telepot from telepot.loop import MessageLoop from sheets import Sheets from telegram import Handler if __name__ == '__main__': logging.basicConfig(level=logging.INFO) with open('config.json') as fh: config = json.load(fh) bot = telepot.Bot(config['telegram']['token']) sheet = Sheets(config['sheets']) # # Optionally register callbacks for new accounting periods here: # sheet.new_ap_supervisor.register_callback() handler = Handler(bot, sheet, config['telegram']) loop = MessageLoop(bot, handler.handle) loop.run_as_thread() while True: time.sleep(10)