Updated db-setup.py

This commit is contained in:
spla 2020-03-21 20:11:45 +01:00
pare cdb4fe6d02
commit 36db04c362

Veure arxiu

@ -29,15 +29,13 @@ def get_parameter( parameter, file_path ):
sys.exit(0)
def write_parameter( parameter, file_path ):
print("Setting up host parameters...")
print("Setting up newsfeed parameters...")
print("\n")
mastodon_hostname = input("Enter Mastodon hostname: ")
feeds_db = input("feeds db name: ")
feeds_db_user = input("feeds db user: ")
feeds_url = input("enter feeds url: ")
with open(file_path, "w") as text_file:
print("mastodon_hostname: {}".format(mastodon_hostname), file=text_file)
print("feeds_db: {}".format(feeds_db), file=text_file)
print("feeds_db_user: {}".format(feeds_db_user), file=text_file)
print("feeds_url: {}".format(feeds_url), file=text_file)
@ -71,8 +69,7 @@ def create_table(db, db_user, table, sql):
#############################################################################################
# Load configuration from config file
config_filepath = "config.txt"
mastodon_hostname = get_parameter("mastodon_hostname", config_filepath)
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)
@ -121,7 +118,7 @@ except (Exception, psycopg2.DatabaseError) as error:
print(error)
# Load configuration from config file
os.remove("config.txt")
os.remove("db_config.txt")
print("Exiting. Run setup again with right parameters")
sys.exit(0)
@ -141,7 +138,7 @@ print("Creating table...")
db = feeds_db
db_user = feeds_db_user
table = "newsfeed"
table = "feeds"
sql = "create table "+table+" (link varchar(200) PRIMARY KEY)"
create_table(db, db_user, table, sql)