Updated db-setup.py
This commit is contained in:
pare
cdb4fe6d02
commit
36db04c362
S'han modificat 1 arxius amb 4 adicions i 7 eliminacions
11
db-setup.py
11
db-setup.py
|
@ -29,15 +29,13 @@ def get_parameter( parameter, file_path ):
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def write_parameter( parameter, file_path ):
|
def write_parameter( parameter, file_path ):
|
||||||
print("Setting up host parameters...")
|
print("Setting up newsfeed parameters...")
|
||||||
print("\n")
|
print("\n")
|
||||||
mastodon_hostname = input("Enter Mastodon hostname: ")
|
|
||||||
feeds_db = input("feeds db name: ")
|
feeds_db = input("feeds db name: ")
|
||||||
feeds_db_user = input("feeds db user: ")
|
feeds_db_user = input("feeds db user: ")
|
||||||
feeds_url = input("enter feeds url: ")
|
feeds_url = input("enter feeds url: ")
|
||||||
|
|
||||||
with open(file_path, "w") as text_file:
|
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: {}".format(feeds_db), file=text_file)
|
||||||
print("feeds_db_user: {}".format(feeds_db_user), file=text_file)
|
print("feeds_db_user: {}".format(feeds_db_user), file=text_file)
|
||||||
print("feeds_url: {}".format(feeds_url), 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
|
# Load configuration from config file
|
||||||
config_filepath = "config.txt"
|
config_filepath = "db_config.txt"
|
||||||
mastodon_hostname = get_parameter("mastodon_hostname", config_filepath)
|
|
||||||
feeds_db = get_parameter("feeds_db", config_filepath)
|
feeds_db = get_parameter("feeds_db", config_filepath)
|
||||||
feeds_db_user = get_parameter("feeds_db_user", config_filepath)
|
feeds_db_user = get_parameter("feeds_db_user", config_filepath)
|
||||||
feeds_url = get_parameter("feeds_url", config_filepath)
|
feeds_url = get_parameter("feeds_url", config_filepath)
|
||||||
|
@ -121,7 +118,7 @@ except (Exception, psycopg2.DatabaseError) as error:
|
||||||
|
|
||||||
print(error)
|
print(error)
|
||||||
# Load configuration from config file
|
# Load configuration from config file
|
||||||
os.remove("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)
|
||||||
|
|
||||||
|
@ -141,7 +138,7 @@ print("Creating table...")
|
||||||
|
|
||||||
db = feeds_db
|
db = feeds_db
|
||||||
db_user = feeds_db_user
|
db_user = feeds_db_user
|
||||||
table = "newsfeed"
|
table = "feeds"
|
||||||
sql = "create table "+table+" (link varchar(200) PRIMARY KEY)"
|
sql = "create table "+table+" (link varchar(200) PRIMARY KEY)"
|
||||||
create_table(db, db_user, table, sql)
|
create_table(db, db_user, table, sql)
|
||||||
|
|
||||||
|
|
Loading…
Referencia en una nova incidència