| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import psycopg2
- import re
- def get_events():
- """Simply retrieve events"""
- query = """SELECT * FROM events
- WHERE timestamp BETWEEN now() - INTERVAL '24 HOURS' AND now()
- AND (news LIKE '% sent an application to join the Faction.'
- OR news LIKE '% left the faction.'
- OR news LIKE '% has accepted %'
- OR news LIKE '% has declined %')
- ORDER BY timestamp DESC;"""
- return query
- def database_select(cur, query):
- results = None
- try:
- cur.execute(query)
- results = cur.fetchall()
- except (Exception, psycopg2.Error) as error:
- print("PostgreSQL error from psycopg2:", error)
- return results
- def database_insert(cur, query):
- try:
- cur.execute(query)
- cur.commit()
- except (Exception, psycopg2.Error) as error:
- print("PostgreSQL error from psycopg2:", error)
- def create_links(news_string):
- regex = re.compile(r'<a href = "?https?://www\.torn\.com/profiles\.php\?XID=(\d+)"?>([^<]+)</a>')
- return_string = re.sub(regex, r'[\2 [\1]](https://www.torn.com/profiles.php?XID=\1)', news_string)
- return return_string
- def is_broadcast(cur, this_id):
- query = f"""SELECT COUNT(*) FROM human_resource WHERE event = {this_id};"""
- res = database_select(cur, query)
- boolean = True if res[0] == 1 else False
- return boolean
- def record_broadcast(cur, event_id):
- query = f"""INSERT INTO human_resource(event) VALUES({event_id});"""
- database_insert(cur, query)
|