refactor the project up to modern standards

This commit is contained in:
Johann Dreo 2026-04-04 14:02:06 +02:00
commit cee043b6d2
2 changed files with 51 additions and 24 deletions

23
pyproject.toml Normal file
View file

@ -0,0 +1,23 @@
[project]
name = "forthlift"
version = "0.1.0"
description = "A command line application to post sequences of text lines on social media"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"argparse>=1.4.0",
"configparser>=7.2.0",
"datetime>=6.0",
]
[project.scripts]
forthlift = "forthlift.forthlift:main"
[build-system]
requires = ["setuptools>=68", "wheel"]
build-backend = "setuptools.build_meta"
[tool.setuptools.packages.find]
where = ["src"]
include = ["forthlift*"]

View file

@ -2,11 +2,12 @@
import sys
import locale
import logging
import argparse
import datetime
import ConfigParser
from configparser import ConfigParser
import tweepy
#import tweepy
class AppKeyError(Exception):
@ -160,24 +161,24 @@ def setup_twitter(configfile="twitter.conf"):
app_key = config.get("App","app_key")
app_secret = config.get("App","app_key_secret")
auth = tweepy.OAuthHandler(app_key, app_secret)
# auth = tweepy.OAuthHandler(app_key, app_secret)
# Authenticate the user.
auth_url = auth.get_authorization_url()
print "Copy and paste this URL in your browser while your are logged in the twitter account where you want to post."
print "Authorization URL: " + auth_url
# auth_url = auth.get_authorization_url()
# print("Copy and paste this URL in your browser while your are logged in the twitter account where you want to post.")
# print("Authorization URL: " + auth_url)
print "Then paste the Personal Identification Number given by Twitter:"
verifier = raw_input('PIN: ').strip()
token = auth.get_access_token(verifier)
# print("Then paste the Personal Identification Number given by Twitter:")
# verifier = raw_input('PIN: ').strip()
# token = auth.get_access_token(verifier)
# Authenticate and get the user name.
token_key, token_secret = token
auth.set_access_token(token_key, token_secret)
api = tweepy.API(auth)
username = api.me().name
print "Authentication successful, ready to post to account: " + username
# token_key, token_secret = token
# auth.set_access_token(token_key, token_secret)
# api = tweepy.API(auth)
# username = api.me().name
# print("Authentication successful, ready to post to account: " + username)
# Save authentication tokens.
@ -200,8 +201,7 @@ def setup_twitter(configfile="twitter.conf"):
# CLI
#
if __name__=="__main__":
def main():
errors = {"NO_ERROR":0, "UNKNOWN_ERROR":1, "NO_SETUP_NEEDED":2, "NO_APP_KEY":10}
usage = "Post text read on the standard input to a website or an API."
@ -261,7 +261,7 @@ if __name__=="__main__":
sys.stderr.write(e.msg)
sys.exit(errors["NO_APP_KEY"])
except:
print "Unexpected error:", sys.exc_info()[0]
logging.error(f"Unexpected error:\n{sys.exc_info()[0]}")
raise
else:
sys.exit(errors["NO_ERROR"])
@ -294,9 +294,9 @@ if __name__=="__main__":
except OSError:
cannot.append(img)
if cannot:
print("Cannot open the following image files, I will not continue: ")
logger.error("Cannot open the following image files, I will not continue: ")
for img in cannot:
print(img)
logger.error(img)
sys.exit(5) # I/O Error
# APIs
@ -321,11 +321,15 @@ if __name__=="__main__":
access_token = config.get("Auth","local_token")
access_token_secret = config.get("Auth","local_token_secret")
auth = tweepy.OAuthHandler(app_key, app_secret, "https://api.twitter.com/1.1/")
auth.set_access_token(access_token, access_token_secret)
# auth = tweepy.OAuthHandler(app_key, app_secret, "https://api.twitter.com/1.1/")
# auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# api = tweepy.API(auth)
# Post
operate( on_twitter, api, asked )
# # Post
# operate( on_twitter, api, asked )
if __name__ == "__main__":
main()