Compare commits
No commits in common. "68b1dbc147f484d7600140d7de53a906f72fcc9d" and "e6b17d38fbdd0ba829ab132e636b35881c61a044" have entirely different histories.
68b1dbc147
...
e6b17d38fb
1 changed files with 11 additions and 27 deletions
38
gen.py
38
gen.py
|
@ -12,42 +12,26 @@ parser.add_argument('-s', '--simulate', dest='simulate', action='store_true',
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if not args.simulate:
|
client = Mastodon(
|
||||||
client = Mastodon(
|
client_id="clientcred.secret",
|
||||||
client_id="clientcred.secret",
|
access_token="usercred.secret",
|
||||||
access_token="usercred.secret",
|
api_base_url="https://botsin.space")
|
||||||
api_base_url="https://botsin.space"
|
|
||||||
)
|
|
||||||
|
|
||||||
db = sqlite3.connect("dict.db")
|
db = sqlite3.connect("dict.db")
|
||||||
db.text_factory=str
|
db.text_factory=str
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
data = c.execute(r'SELECT word, definition FROM entries WHERE word LIKE "%ar%" AND wordtype LIKE "n." AND definition NOT LIKE "See%" AND definition NOT LIKE "Alt.%"').fetchall()
|
data = c.execute(r'SELECT word, definition FROM entries WHERE word LIKE "%ar%" AND wordtype LIKE "n."').fetchall()
|
||||||
dset = random.choice(data)
|
dset = random.choice(data)
|
||||||
definition = dset[1].replace("\n ", "") # remove newlines from definitions
|
toot = "What's a pirate's favourite {}?\nA {}!".format(
|
||||||
definition = definition.replace("etc.", "etc") # remove full stop from etc so as not to confuse the """algorithm"""
|
re.search(r"^([^.]+)", dset[1]).group(1).replace("\n ", ""), dset[0].lower().replace("ar", "a" + ('r' * random.randint(3,10)))
|
||||||
definition = re.search(r"^(?:An?|The)? ?([^.]*)", definition).group(1) # remove leading "A", "An", and "The", and stop at the first full stop
|
|
||||||
definition = definition[0].lower() + definition[1:] # make first letter lowercase
|
|
||||||
if " " not in definition:
|
|
||||||
# "what's a pirate's favourite disembarkation? a debarrrkation!" doesn't make sense
|
|
||||||
# so replace single words with "alternate word for {word}"
|
|
||||||
# example: "what's a pirate's favourite alternate word for disembarkation? a debarrrkation!"
|
|
||||||
# not perfect but much better
|
|
||||||
definition = "alternative word for {}".format(definition)
|
|
||||||
cw = "What's a pirate's favourite {}?".format(definition)
|
|
||||||
toot = "A {}!".format(
|
|
||||||
dset[0].lower().replace("ar", "a" + ('r' * random.randint(3,10)))
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if not args.simulate:
|
if not args.simulate:
|
||||||
try:
|
try:
|
||||||
client.status_post(toot, visibility = 'unlisted', spoiler_text = cw)
|
client.status_post(toot, visibility = 'unlisted')
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
toot = "Arr, @lynnesbian@fedi.lynnesbian.space, ye scallywag!" \
|
toot = "Mistress @lynnesbian@fedi.lynnesbian.space, something has gone terribly" \
|
||||||
+ " I've encountered an error most dire!" \
|
+ " wrong! While attempting to post a toot, I received the following" \
|
||||||
+ " Check error.log in ye bot directory!!"
|
+ " error:\n" + "\n".join(traceback.format_tb(sys.exc_info()[2]))
|
||||||
with open("error.log", "w") as f:
|
|
||||||
f.write("\n".join(traceback.format_tb(sys.exc_info()[2])))
|
|
||||||
client.status_post(toot, visibility = 'unlisted', spoiler_text = "Error!")
|
client.status_post(toot, visibility = 'unlisted', spoiler_text = "Error!")
|
||||||
print(cw)
|
|
||||||
print(toot)
|
print(toot)
|
||||||
|
|
Loading…
editor.table_modal.header
Reference in a new issue