def rmTask(id): with sqlite3.connect(PATH_TO_DATABASE) as db: cursor = db.cursor() cursor.execute("""SELECT tableID, title FROM tasks WHERE id=?""", (id, )) task = cursor.fetchall()[0] cursor.execute("""DELETE FROM tasks WHERE id=?""", (id, )) db.commit() Tables.updateTable(task[0]) return task[1]
def query(self, type='all'): Tables.query(self) committees = pyopenstates.search_committees(state=config.STATE) self.raw_dictionary = map( lambda comm_dic: pyopenstates.get_committee( comm_dic['id'], fields=[ 'id', 'chamber', 'sources', 'subcommittee', 'committee', 'parent_id' ]), committees)
def changeStatus(id): with sqlite3.connect(PATH_TO_DATABASE) as db: cursor = db.cursor() createDate = getDateNowTimestamp() cursor.execute("""SELECT tableID, status FROM tasks WHERE id=?""", (id, )) task = cursor.fetchall()[0] status = 0 if int(task[1]) else 1 cursor.execute( """UPDATE tasks SET changeDate = ?, status = ? WHERE id = ?""", (createDate, status, id)) Tables.updateTable(task[0]) db.commit()
def create(tableID, title, status=0, description=""): with sqlite3.connect(PATH_TO_DATABASE) as db: cursor = db.cursor() createDate = getDateNowTimestamp() print(status) cursor.execute( """INSERT INTO tasks(tableID, title, creationDate, changeDate, status, description) VALUES(?,?,?,?,?,?)""", (tableID, title, createDate, createDate, status, description)) cursor.execute( """SELECT id FROM tasks WHERE title LIKE ? ORDER BY id DESC""", (title, )) id = cursor.fetchall()[0][0] db.commit() Tables.updateTable(tableID) return id
def query(self, type='active', term_name=None): """ Obtains raw data of legislators, defaults to active legislators from the latest term Args: term_name: term name as it comes from OpenStates API type: Either 'all' or 'active' Returns: String transformed """ Tables.query(self) if type == 'all': if term_name is None: metadata = Metadata() term_name = metadata.latest_term_name legislators = pyopenstates.search_legislators(state=config.STATE, term=term_name, fields='id') else: # 'active' legislators = pyopenstates.search_legislators( state=config.STATE, active='true', # default fields='id') self.raw_dictionary = map( lambda dic: pyopenstates.get_legislator( dic['id'], fields=[ 'id', 'full_name', 'url', 'roles', # 'old_roles', 'party', 'district', 'chamber', 'offices', 'email' ]), legislators)
def query(self, session='session' ): # default 'session' returns only current session Tables.query(self) bills = pyopenstates.search_bills( state=config.STATE, search_window=session, type="bill", # chamber="upper", # lower # updated_since="YYYY-MM-DD", # subject="", # sponsor_id="000000", sort="created_at", fields='id') self.raw_dictionary = map( lambda dic: pyopenstates.get_bill( dic['id'], fields=[ 'id', 'bill_id', 'chamber', '+short_title', 'actions', 'action_dates', 'session', 'sources', 'sponsors', 'subjects', 'title', 'votes' ]), bills)
def __init__(self): Tables.__init__(self) self.template_name = 'Infobox legislator'
def __init__(self): Tables.__init__(self) self.template_name = 'Infobox committee'
def __init__(self): Tables.__init__(self) self.template_name = 'Infobox bill'
initDB() hello() while True: cmd = input("> ").split(" ") if cmd[0] in exitCommands: quit() elif cmd[0] in helpCommands: print(helpText) elif cmd[0] in createTableCommands: try: id = Tables.create(cmd[1]) print("Table \"{}\" created. ID = {}".format(cmd[1], id)) except: error() elif cmd[0] in createTaskCommands: try: id = Tasks.create(*cmd[1:4:], " ".join( cmd[4::])) if len(cmd) > 3 else Tasks.create( cmd[1], cmd[2]) print("Task \"{}\" created. ID = {}".format(cmd[2], id)) except: error() elif cmd[0] in listTableCommands: try:
def __init__(self): Tables.__init__(self) self.template_name = 'Relation:LegislatorVote'
def __init__(self): Tables.__init__(self) self.template_name = 'Relation:BillSponsor'