Increased link column to varchar(300)

This commit is contained in:
spla 2021-05-15 11:30:59 +02:00
commit c9219f1a85
S'han modificat 4 arxius amb 314 adicions i 298 eliminacions

Veure arxiu

@ -7,21 +7,20 @@ Publish to Mastodon's server the rss feed of your choice.
- **Python 3**
- Postgresql server
- Everything else at the top of `mastofeeds.py`!
- Mastodon's bot account
### Usage:
Within Python Virtual Environment:
1. Run 'python db-setup.py' to create needed database and table. It's needed to control what feeds are already published. db-setup.py
1. Run `pip install -r requirements.txt` to install all needed libraries.
2. Run `python db-setup.py` to create needed database and table. It's needed to control what feeds are already published. db-setup.py
will also ask you the feed's url.
2. Run 'python setup.py' to get your bot's access token of an existing user. It will be saved to 'secrets/secrets.txt' for further use.
3. Run `python setup.py` to get your bot's access token of an existing user. It will be saved to 'secrets/secrets.txt' for further use.
3. Run 'python mastofeeds.py' to start publishing feeds.
4. Use your favourite scheduling method to set mastofeeds.py to run regularly.
Note: install all needed packages with 'pip install package' or use 'pip install -r requirements.txt' to install them.
4. Run `python mastofeeds.py` to start publishing feeds.
5. Use your favourite scheduling method to set `python mastofeeds.py` to run regularly.

Veure arxiu

@ -66,7 +66,10 @@ def create_table(db, db_user, table, sql):
conn.close()
#############################################################################################
###############################################################################
# main
if __name__ == '__main__':
# Load configuration from config file
config_filepath = "db_config.txt"
@ -82,9 +85,7 @@ conn = None
try:
conn = psycopg2.connect(dbname='postgres',
user=feeds_db_user, host='',
password='')
conn = psycopg2.connect(dbname='postgres', user=feeds_db_user, host='', password='')
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
@ -92,9 +93,8 @@ try:
print("Creating database " + feeds_db + ". Please wait...")
cur.execute(sql.SQL("CREATE DATABASE {}").format(
sql.Identifier(feeds_db))
)
cur.execute(sql.SQL("CREATE DATABASE {}").format(sql.Identifier(feeds_db)))
print("Database " + feeds_db + " created!")
except (Exception, psycopg2.DatabaseError) as error:
@ -117,6 +117,7 @@ try:
except (Exception, psycopg2.DatabaseError) as error:
print(error)
# Load configuration from config file
os.remove("db_config.txt")
print("Exiting. Run setup again with right parameters")
@ -134,7 +135,7 @@ if conn is not None:
print("Creating table...")
########################################
#####################################
db = feeds_db
db_user = feeds_db_user

Veure arxiu

@ -3,10 +3,7 @@ import feedparser
from mastodon import Mastodon
import psycopg2
import sys
###############################################################################
# INITIALISATION
###############################################################################
import time
# Returns the parameter from the specified file
def get_parameter( parameter, file_path ):
@ -25,6 +22,11 @@ def get_parameter( parameter, file_path ):
print(file_path + " Missing parameter %s "%parameter)
sys.exit(0)
###############################################################################
# main
if __name__ == '__main__':
# Load secrets from secrets file
secrets_filepath = "secrets/secrets.txt"
uc_client_id = get_parameter("uc_client_id", secrets_filepath)
@ -52,11 +54,19 @@ mastodon = Mastodon(
# Initialise access headers
headers={ 'Authorization': 'Bearer %s'%uc_access_token }
########################################################
#######################################################################
publish = 0
try:
newsfeeds = feedparser.parse(feeds_url)
print(newsfeeds.status)
except:
print(newsfeeds.status)
sys.exit(0)
for entry in newsfeeds.entries:
@ -66,7 +76,6 @@ for entry in newsfeeds.entries:
###################################################################
# check database if feed is already published
###################################################################
try:
@ -75,7 +84,7 @@ for entry in newsfeeds.entries:
cur = conn.cursor()
cur.execute('select link from feeds where link=(%s)', (link,))
cur.execute('select id from feeds where id=(%s)', (id,))
row = cur.fetchone()
if row == None:
@ -107,9 +116,11 @@ for entry in newsfeeds.entries:
mastodon.status_post(toot_text, in_reply_to_id=None,)
time.sleep(2)
#########################################################
insert_line = 'INSERT INTO feeds(link) VALUES (%s)'
insert_line = 'INSERT INTO feeds(id, link) VALUES (%s, %s)'
conn = None
@ -119,7 +130,7 @@ for entry in newsfeeds.entries:
cur = conn.cursor()
cur.execute(insert_line, (link,))
cur.execute(insert_line, (id, link,))
conn.commit()
@ -137,3 +148,4 @@ for entry in newsfeeds.entries:
else:
print("Any new feeds")
sys.exit(0)

Veure arxiu

@ -114,7 +114,6 @@ def log_in():
sys.exit(a_error)
finally:
if error == 0:
create_dir()
create_file()
write_params()
@ -175,6 +174,11 @@ def get_hostname( parameter, config_filepath ):
print("hostname setup done!")
sys.exit(0)
###############################################################################
# main
if __name__ == '__main__':
# Load secrets from secrets file
secrets_filepath = "secrets/secrets.txt"
uc_client_id = get_parameter("uc_client_id", secrets_filepath)
@ -183,4 +187,4 @@ uc_access_token = get_parameter("uc_access_token", secrets_filepath)
# Load configuration from config file
config_filepath = "config.txt"
mastodon_hostname = get_hostname("mastodon_hostname", config_filepath) # E.g., mastodon.social
mastodon_hostname = get_hostname("mastodon_hostname", config_filepath)