refactor the project up to modern standards
This commit is contained in:
parent
913e0b552e
commit
cee043b6d2
2 changed files with 51 additions and 24 deletions
23
pyproject.toml
Normal file
23
pyproject.toml
Normal 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*"]
|
||||||
|
|
||||||
|
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import locale
|
import locale
|
||||||
|
import logging
|
||||||
import argparse
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
import tweepy
|
#import tweepy
|
||||||
|
|
||||||
|
|
||||||
class AppKeyError(Exception):
|
class AppKeyError(Exception):
|
||||||
|
|
@ -160,24 +161,24 @@ def setup_twitter(configfile="twitter.conf"):
|
||||||
app_key = config.get("App","app_key")
|
app_key = config.get("App","app_key")
|
||||||
app_secret = config.get("App","app_key_secret")
|
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.
|
# Authenticate the user.
|
||||||
auth_url = auth.get_authorization_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("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("Authorization URL: " + auth_url)
|
||||||
|
|
||||||
print "Then paste the Personal Identification Number given by Twitter:"
|
# print("Then paste the Personal Identification Number given by Twitter:")
|
||||||
verifier = raw_input('PIN: ').strip()
|
# verifier = raw_input('PIN: ').strip()
|
||||||
token = auth.get_access_token(verifier)
|
# token = auth.get_access_token(verifier)
|
||||||
|
|
||||||
# Authenticate and get the user name.
|
# Authenticate and get the user name.
|
||||||
token_key, token_secret = token
|
# token_key, token_secret = token
|
||||||
auth.set_access_token(token_key, token_secret)
|
# auth.set_access_token(token_key, token_secret)
|
||||||
api = tweepy.API(auth)
|
# api = tweepy.API(auth)
|
||||||
username = api.me().name
|
# username = api.me().name
|
||||||
print "Authentication successful, ready to post to account: " + username
|
# print("Authentication successful, ready to post to account: " + username)
|
||||||
|
|
||||||
|
|
||||||
# Save authentication tokens.
|
# Save authentication tokens.
|
||||||
|
|
@ -200,8 +201,7 @@ def setup_twitter(configfile="twitter.conf"):
|
||||||
# CLI
|
# CLI
|
||||||
#
|
#
|
||||||
|
|
||||||
if __name__=="__main__":
|
def main():
|
||||||
|
|
||||||
errors = {"NO_ERROR":0, "UNKNOWN_ERROR":1, "NO_SETUP_NEEDED":2, "NO_APP_KEY":10}
|
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."
|
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.stderr.write(e.msg)
|
||||||
sys.exit(errors["NO_APP_KEY"])
|
sys.exit(errors["NO_APP_KEY"])
|
||||||
except:
|
except:
|
||||||
print "Unexpected error:", sys.exc_info()[0]
|
logging.error(f"Unexpected error:\n{sys.exc_info()[0]}")
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
sys.exit(errors["NO_ERROR"])
|
sys.exit(errors["NO_ERROR"])
|
||||||
|
|
@ -294,9 +294,9 @@ if __name__=="__main__":
|
||||||
except OSError:
|
except OSError:
|
||||||
cannot.append(img)
|
cannot.append(img)
|
||||||
if cannot:
|
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:
|
for img in cannot:
|
||||||
print(img)
|
logger.error(img)
|
||||||
sys.exit(5) # I/O Error
|
sys.exit(5) # I/O Error
|
||||||
|
|
||||||
# APIs
|
# APIs
|
||||||
|
|
@ -321,11 +321,15 @@ if __name__=="__main__":
|
||||||
access_token = config.get("Auth","local_token")
|
access_token = config.get("Auth","local_token")
|
||||||
access_token_secret = config.get("Auth","local_token_secret")
|
access_token_secret = config.get("Auth","local_token_secret")
|
||||||
|
|
||||||
auth = tweepy.OAuthHandler(app_key, app_secret, "https://api.twitter.com/1.1/")
|
# auth = tweepy.OAuthHandler(app_key, app_secret, "https://api.twitter.com/1.1/")
|
||||||
auth.set_access_token(access_token, access_token_secret)
|
# auth.set_access_token(access_token, access_token_secret)
|
||||||
|
|
||||||
api = tweepy.API(auth)
|
# api = tweepy.API(auth)
|
||||||
|
|
||||||
# Post
|
# # Post
|
||||||
operate( on_twitter, api, asked )
|
# operate( on_twitter, api, asked )
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue