-
Notifications
You must be signed in to change notification settings - Fork 51
/
initialize_bot.py
66 lines (50 loc) · 2.1 KB
/
initialize_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# initialize_bot.py
import os
import sys
import argparse
import json
from instagram_util.hashtags import get_related_hashtags
def create_directory_structure(username):
base_path = f"accounts/{username}"
os.makedirs(base_path, exist_ok=True)
os.makedirs(f"{base_path}/queue", exist_ok=True)
os.makedirs(f"{base_path}/archive", exist_ok=True)
return base_path
def save_config(username, password, api_key, summary, hashtags, path):
config = {
"username": username,
"password": password,
"api_key": api_key,
"summary": summary,
"hashtags": hashtags
}
with open(f"{path}/config.json", "w") as config_file:
json.dump(config, config_file, indent=2)
def create_prompt_file(username, summary, hashtags, path):
with open("master_prompt.txt", "r") as master_prompt_file:
master_prompt = master_prompt_file.read()
master_prompt = master_prompt.replace("INSTAGRAM_USERNAME", username)
master_prompt = master_prompt.replace("ACCOUNT_SUMMARY", summary)
master_prompt = master_prompt.replace("RELATED_HASHTAGS", hashtags)
with open(f"{path}/prompt.txt", "w") as prompt_file:
prompt_file.write(master_prompt)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("username", help="Instagram username")
parser.add_argument("password", help="Instagram password")
parser.add_argument("api_key", help="GPT API key")
args = parser.parse_args()
username = args.username
password = args.password
api_key = args.api_key
summary = input("Please enter an account summary: ")
# force at least one hashtag
hashtags_input = ''
while not hashtags_input.strip():
hashtags_input = input("Please enter at least one related hashtag separated by commas: ")
hashtags = get_related_hashtags([hashtag.strip().replace('#', '') for hashtag in hashtags_input.split(',')])
path = create_directory_structure(username)
save_config(username, password, api_key, summary, hashtags, path)
create_prompt_file(username, summary, hashtags, path)
if __name__ == "__main__":
main()