Copying over setup stuff from romeotools

This commit is contained in:
Klaus-Uwe Mitterer 2017-02-08 21:57:24 +01:00
parent 9b0186ee44
commit 8815c41515
2 changed files with 78 additions and 0 deletions

31
setup.py Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env python3
import configparser, os.path, tweepy, dbtools, getpass
if os.path.isfile("config.cfg"):
print("config.cfg already exists. Please remove it before running this script.")
exit(1)
config = configparser.RawConfigParser()
config.add_section("Romeo")
print('''In the next step, we'll get you connected to Read.it. For this, we
will need your username and password. Please note that these will be stored on
your hard disk in plain text. Sadly Read.it doesn't offer a better way for
third party applications to authenticate...
''')
unam = input("Username: ")
pwrd = getpass.getpass("Password (not echoed back!): ")
print()
config.set("Read.it", "user", unam)
config.set("Read.it", "pass", pwrd)
print("Seems like everything worked out fine. Let's write that config file...")
with open('config.cfg', 'wt') as cfg:
config.write(cfg)
print("We're all done. You can now use the Read.it exporter. Have fun!")

47
setuptools/__init__.py Normal file
View file

@ -0,0 +1,47 @@
import configparser, csv, datetime, html.parser, itertools, os, sqlite3, sys
class SetupException(Exception):
def __str__(self):
return "Seems like config.cfg has not been created yet or contains serious errors. Run setup.py to create it."
def getSetting(section, setting, path = "config.cfg"):
config = configparser.RawConfigParser()
config.read(path)
return config.get(section, setting)
def riuser():
try:
return getSetting("Read.it", "user")
except:
raise SetupException()
def ripass():
try:
return getSetting("Read.it", "pass")
except:
raise SetupException()
def fileExists(path):
return os.path.isfile(path)
def getDate(date):
try:
return datetime.datetime.strptime(date, '%Y-%m-%d')
except ValueError:
raise ValueError("Dates must be in YYYY-MM-DD format.")
def paginate(iterable, page_size):
while True:
i1, i2 = itertools.tee(iterable)
iterable, page = (itertools.islice(i1, page_size, None), list(itertools.islice(i2, page_size)))
if len(page) == 0:
break
yield page
def printCSV(inlist):
writer = csv.writer(sys.stdout)
writer.writerows(inlist)
def unescapeText(text):
return html.parser.HTMLParser().unescape(text).replace("'","''")