Fixed indents

This commit is contained in:
spla 2020-10-20 12:54:34 +02:00
pare 70b8575fe5
commit c65a4c1fc8
S'han modificat 2 arxius amb 116 adicions i 112 eliminacions

Veure arxiu

@ -66,25 +66,26 @@ def create_table(db, db_user, table, sql):
conn.close() conn.close()
############################################################################################# ###############################################################################
# main
# Load configuration from config file if __name__ == '__main__':
config_filepath = "db_config.txt"
feeds_db = get_parameter("feeds_db", config_filepath)
feeds_db_user = get_parameter("feeds_db_user", config_filepath)
feeds_url = get_parameter("feeds_url", config_filepath)
############################################################ # Load configuration from config file
# create database config_filepath = "db_config.txt"
############################################################ feeds_db = get_parameter("feeds_db", config_filepath)
feeds_db_user = get_parameter("feeds_db_user", config_filepath)
feeds_url = get_parameter("feeds_url", config_filepath)
conn = None ############################################################
# create database
############################################################
try: conn = None
conn = psycopg2.connect(dbname='postgres', try:
user=feeds_db_user, host='',
password='') conn = psycopg2.connect(dbname='postgres', user=feeds_db_user, host='', password='')
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
@ -92,58 +93,58 @@ try:
print("Creating database " + feeds_db + ". Please wait...") print("Creating database " + feeds_db + ". Please wait...")
cur.execute(sql.SQL("CREATE DATABASE {}").format( cur.execute(sql.SQL("CREATE DATABASE {}").format(sql.Identifier(feeds_db)))
sql.Identifier(feeds_db))
)
print("Database " + feeds_db + " created!") print("Database " + feeds_db + " created!")
except (Exception, psycopg2.DatabaseError) as error: except (Exception, psycopg2.DatabaseError) as error:
print(error) print(error)
finally: finally:
if conn is not None: if conn is not None:
conn.close() conn.close()
############################################################################################# #############################################################################################
try: try:
conn = None conn = None
conn = psycopg2.connect(database = feeds_db, user = feeds_db_user, password = "", host = "/var/run/postgresql", port = "5432") conn = psycopg2.connect(database = feeds_db, user = feeds_db_user, password = "", host = "/var/run/postgresql", port = "5432")
except (Exception, psycopg2.DatabaseError) as error: except (Exception, psycopg2.DatabaseError) as error:
print(error) print(error)
# Load configuration from config file # Load configuration from config file
os.remove("db_config.txt") os.remove("db_config.txt")
print("Exiting. Run setup again with right parameters") print("Exiting. Run setup again with right parameters")
sys.exit(0) sys.exit(0)
if conn is not None: if conn is not None:
print("\n") print("\n")
print("Host parameters saved to config.txt!") print("Host parameters saved to config.txt!")
print("\n") print("\n")
############################################################ ############################################################
# Create needed tables # Create needed tables
############################################################ ############################################################
print("Creating table...") print("Creating table...")
######################################## ########################################
db = feeds_db db = feeds_db
db_user = feeds_db_user db_user = feeds_db_user
table = "feeds" table = "feeds"
sql = "create table "+table+" (id varchar(200) PRIMARY KEY, link varchar(250))" sql = "create table "+table+" (id varchar(200) PRIMARY KEY, link varchar(250))"
create_table(db, db_user, table, sql) create_table(db, db_user, table, sql)
##################################### #####################################
print("Done!") print("Done!")
print("Now you can run setup.py!") print("Now you can run setup.py!")
print("\n") print("\n")

Veure arxiu

@ -52,13 +52,16 @@ mastodon = Mastodon(
# Initialise access headers # Initialise access headers
headers={ 'Authorization': 'Bearer %s'%uc_access_token } headers={ 'Authorization': 'Bearer %s'%uc_access_token }
######################################################## ###############################################################################
# main
publish = 0 if __name__ == '__main__':
newsfeeds = feedparser.parse(feeds_url) publish = 0
for entry in newsfeeds.entries: newsfeeds = feedparser.parse(feeds_url)
for entry in newsfeeds.entries:
title = entry['title'] title = entry['title']
id = entry['id'] id = entry['id']