chore: Init

This commit is contained in:
NaiJi ✨ 2023-03-06 06:26:58 +01:00
commit e55cf2c275
7 changed files with 169 additions and 0 deletions

1
.gitignore vendored Normal file
View File

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

72
markov.cpp Normal file
View File

@ -0,0 +1,72 @@
#include <iostream>
#include <vector>
#include <map>
#include <deque>
#include <string>
#include <random>
#include <ctime>
using namespace std;
using prefix = deque<string>;
constexpr int NPREF = 2;
constexpr int MAXGEN = 10000;
const string NOWORD = "\n";
static map<prefix, vector<string>> statetab;
void add(prefix& p, const string& s)
{
if (p.size() == NPREF) {
statetab[p].emplace_back(s);
p.pop_front();
}
p.emplace_back(s);
}
void build(prefix& p, istream& in)
{
string buf;
while (in >> buf)
add(p, buf);
}
void generate(const int nwords)
{
prefix p;
int i;
mt19937_64 rng;
rng.seed(unsigned(time(nullptr)));
for (i = 0; i < NPREF; ++i)
add(p, NOWORD);
for (i = 0; i < nwords; ++i) {
const vector<string>& suf = statetab[p];
const string& w = suf[rng() % suf.size()];
if (w == NOWORD)
break;
cout << w << "\n";
p.pop_front();
p.emplace_back(w);
}
}
int
main(int argc, char *argv[])
{
constexpr int nwords = MAXGEN;
prefix current;
for (int i = 0; i < NPREF; ++i)
add(current, NOWORD);
build(current, cin);
add(current, NOWORD);
generate(nwords);
return 0;
}

0
parse.py Normal file
View File

53
post.py Executable file
View File

@ -0,0 +1,53 @@
#!/home/naiji/mastodon/maritalk-bot/venv/bin/python
import sys
import numpy as np
from mastodon import Mastodon
# --------------------------------------------------
def main():
mastodon = Mastodon(
access_token = 'token.dat',
api_base_url = 'https://udongein.xyz/'
)
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())

38
requirements.txt Normal file
View File

@ -0,0 +1,38 @@
acme==1.1.0
certbot==0.40.0
certbot-nginx==0.40.0
certifi==2019.11.28
chardet==3.0.4
ConfigArgParse==0.13.0
configobj==5.0.6
cryptography==2.8
dbus-python==1.2.16
distro==1.4.0
distro-info===0.23ubuntu1
future==0.18.2
idna==2.8
josepy==1.2.0
mock==3.0.5
netifaces==0.10.4
parsedatetime==2.4
pbr==5.4.5
PyGObject==3.36.0
pymacaroons==0.13.0
PyNaCl==1.3.0
pyOpenSSL==19.0.0
pyparsing==2.4.6
pyRFC3339==1.1
python-apt==2.0.0+ubuntu0.20.4.1
python-debian===0.1.36ubuntu1
pytz==2019.3
PyYAML==5.3.1
requests==2.22.0
requests-toolbelt==0.8.0
six==1.14.0
ubuntu-advantage-tools==20.3
ufw==0.36
urllib3==1.25.8
zope.component==4.3.0
zope.event==4.4
zope.hookable==5.0.0
zope.interface==4.7.1

4
runner Normal file
View File

@ -0,0 +1,4 @@
#!/bin/bash
source venv/bin/activate
python3 post.py
deactivate

1
source.dat Normal file

File diff suppressed because one or more lines are too long