configuration related

This commit is contained in:
array-in-a-matrix 2022-02-13 18:21:18 -05:00
parent 64d0f53c09
commit b79197bd6b
5 changed files with 40 additions and 17 deletions

View file

@ -1,9 +1,26 @@
# Instagram Markov Chatbot
An Instagram chat bot which generates new sentences from direct messages.
Currently bot uses a sentences from `dataset.txt` file to generate new sentences.
Code takes an optional argument (integer) that determine the length of the sentence.
An Instagram chat bot which generates new sentences and sends them in direct messages.
Used code from [here](https://towardsdatascience.com/simulating-text-with-markov-chains-in-python-1a27e6d13fc6) as a base.
In the `login.json` file please place your account username and password in the `username` and `password` entries respectively.
The bot will message the top most recent *n<sup>th</sup>* chat, where the *n<sup>th</sup>* chat is the number chosen in the `recent` entry.
If you want to run the program headlessly append `MOZ_HEADLESS=1` to the beginning of the command.
## Configuration
### JSON
- **`username`** / **`password`**
- In the `login.json` file please place your account username and password in the `username` and `password` entries respectively.
- **`dataset`**
- This is the path to the text file which will be used to generate messages.
- **`recent`**
- The bot will message the top most recent *n<sup>th</sup>* chat, where the *n<sup>th</sup>* chat is the number chosen in the `recent` entry.
- **`interval`**
- The `interval` entry controls how often the bot sends a message in seconds.
### Command-line
- **`headless`**
- If you want to run the program headlessly append `MOZ_HEADLESS=1` to the beginning of the command.
- **`message length`**
- Optional argument (integer) that determine the length of the sentence. If no argument is provided or a non integer number was given, messages will generate with variable length between 1 and 30.

10
config.py Normal file
View file

@ -0,0 +1,10 @@
import json
with open('login.json', 'r') as file:
json_object = json.load(file)
username = json_object['username']
password = json_object['password']
dataset = json_object['dataset']
recent = json_object['recent']
interval = json_object['interval']

View file

@ -1,5 +1,7 @@
{
"username": "______",
"password": "______",
"recent": 10
"dataset": "dataset.txt",
"recent": 10,
"interval": 600
}

View file

@ -1,5 +1,6 @@
import sys
import json
from config import username, password, recent, interval
from markov import markov
from time import sleep
from numpy.random import randint
@ -18,14 +19,6 @@ try:
except IndexError:
print("No length given.")
with open('login.json', 'r') as file:
json_object = json.load(file)
username = json_object['username']
password = json_object['password']
recent = json_object['recent']
browser = webdriver.Firefox()
browser.implicitly_wait(5)
browser.get('https://www.instagram.com/')
@ -67,6 +60,6 @@ while True:
browser.find_element(By.CSS_SELECTOR, "[placeholder='Message...']").send_keys(
message + Keys.ENTER)
sleep(20)
sleep(interval)
browser.close()

View file

@ -1,6 +1,7 @@
import numpy as np
from config import dataset
def markov(length=np.random.randint(30), dataset="dataset.txt"):
def markov(length=np.random.randint(30), dataset=dataset):
chatbot = open(dataset, encoding='utf8').read().split()