Browse Source

Init

master
NaiJi 10 months ago
commit
547278dd5c
  1. 1
      .gitignore
  2. 24
      LICENSE
  3. 11
      README.md
  4. 52
      post.py
  5. 1
      source.dat

1
.gitignore

@ -0,0 +1 @@
token.dat

24
LICENSE

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

11
README.md

@ -0,0 +1,11 @@
# maritalk-bot
Just another bot on Markov chains.
Currently posting on: https://social.inex.rocks/@MarisaTalkBot
### How to run ###
* Marisa grabs the text from `source.dat` file. Make sure to fill it with the sentences and word combinations you want!
* To make a single post with a random sentence from the source file, run `post.py`
* Don't forget to setup your bot account, get access tokens and establish the environment around it. I am not providing any instructions of how to do it, since all the steps are different and depend on what, where and how you want to run the bot.
* That's all!

52
post.py

@ -0,0 +1,52 @@
import sys
import numpy as np
from mastodon import Mastodon
# --------------------------------------------------
def main():
mastodon = Mastodon(
access_token = 'token.dat',
api_base_url = 'https://social.inex.rocks/'
)
text = open('source.dat', encoding='utf8').read()
# ORIGINAL IMPLEMENTATION:
# https://gist.github.com/bpshaver/840d53222b72d2612ddf6702ef020274#file-markov_text_sim-py
source = text.split()
def make_pairs(source):
for i in range(len(source)-1):
yield (source[i], source[i+1])
pairs = make_pairs(source)
word_dict = {}
for left_w, right_w in pairs:
if left_w in word_dict.keys():
word_dict[left_w].append(right_w)
else:
word_dict[left_w] = [right_w]
first_word = np.random.choice(source)
while first_word.islower():
first_word = np.random.choice(source)
chain = [first_word]
ch = ''
while not ch.endswith('.'):
ch = np.random.choice(word_dict[chain[-1]])
chain.append(ch)
toot = ' '.join(chain)
mastodon.status_post(toot, media_ids=None, visibility='unlisted')
if __name__ == '__main__':
sys.exit(main())

1
source.dat

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save