It's a fork now
Most notably, I've moved a bunch of options to a separate config file and added the ability to not use a CW by leaving that field blank. Plus updated the README
This commit is contained in:
parent
2618b264f3
commit
2c6858e306
5 changed files with 65 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
|||
*.json
|
||||
*.py[oc]
|
||||
/config__.py
|
||||
/secrets__.py
|
||||
/venv
|
||||
/cron.log
|
||||
|
|
15
config__.default.py
Normal file
15
config__.default.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
model_file = "model.json"
|
||||
# Path to the model generated by import_misskey.py
|
||||
# I had to use absolute paths to get the cronjob to work (ie. /path/to/file.json instead of just file.json)
|
||||
|
||||
instance_url = "example.com"
|
||||
# Domain of the instance the bot is on, eg. botsin.space
|
||||
|
||||
cw = "markov bot generated post"
|
||||
# Content warning to put on the bot's posts
|
||||
|
||||
character_limit = 80
|
||||
# Maximum length of the posts
|
||||
|
||||
log_length = 96
|
||||
# Currently unused
|
24
generate.py
24
generate.py
|
@ -3,21 +3,25 @@ import sys
|
|||
import requests
|
||||
|
||||
import secrets__
|
||||
import config__
|
||||
|
||||
model_f = open("model.json")
|
||||
model_f = open(config__.model_file)
|
||||
model = chain.Text.from_json(model_f.read())
|
||||
|
||||
generated = False
|
||||
text = None
|
||||
|
||||
while not generated:
|
||||
text = model.make_short_sentence(80, tries=900, min_words=3)
|
||||
text = model.make_short_sentence(config__.character_limit, tries=900, min_words=3)
|
||||
generated = text is not None
|
||||
|
||||
text = text.replace('@','@').replace('#','#')
|
||||
print(text)
|
||||
|
||||
requests.post("https://brain.d.on-t.work/api/notes/create", json={
|
||||
apicreate = "https://" + config__.instance_url + "/api/notes/create"\
|
||||
|
||||
if(config__.cw == ""):
|
||||
requests.post(apicreate, json={
|
||||
'i': secrets__.TOKEN,
|
||||
|
||||
'visibility': 'home',
|
||||
|
@ -25,5 +29,15 @@ requests.post("https://brain.d.on-t.work/api/notes/create", json={
|
|||
'noExtractHashtags': True,
|
||||
|
||||
'text': text,
|
||||
'cw': 'markov chain generated post'
|
||||
})
|
||||
})
|
||||
else:
|
||||
requests.post(apicreate, json={
|
||||
'i': secrets__.TOKEN,
|
||||
|
||||
'visibility': 'home',
|
||||
'noExtractMentions': True,
|
||||
'noExtractHashtags': True,
|
||||
|
||||
'text': text,
|
||||
'cw': config__.cw
|
||||
})
|
25
readme.md
Normal file
25
readme.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
Basic Markov bot for Misskey. Fork of https://activitypub.software/kopper/markov
|
||||
|
||||
## Setup
|
||||
|
||||
- Install dependencies:
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
python -m spacy download en_core_web_sm
|
||||
```
|
||||
- Export your notes from Misskey and generate a model:
|
||||
```
|
||||
python import-misskey.py notes-XXXX-XX-XX-XX-XX-XX.json
|
||||
```
|
||||
- Generate an API token for the bot account and use it here:
|
||||
```
|
||||
echo "TOKEN='yourtoken'" > secrets__.py
|
||||
```
|
||||
- Copy `config__.default.py` to `config__.py` and edit as needed
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
python generate.py
|
||||
```
|
||||
Point a cronjob to this file to post automatically
|
|
@ -1,5 +0,0 @@
|
|||
pip install -r requirements.txt
|
||||
python -m spacy download en_core_web_sm
|
||||
python import-misskey.py notes-XXXX-XX-XX-XX-XX-XX.json
|
||||
echo "TOKEN=''" > secrets__.py
|
||||
python generate.py
|
Loading…
Reference in a new issue