-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathig_tools.py
More file actions
76 lines (67 loc) · 2.17 KB
/
ig_tools.py
File metadata and controls
76 lines (67 loc) · 2.17 KB
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
67
68
69
70
71
72
73
74
75
76
from email.policy import default
import os
import json
import mimetypes
import functools
import click
from ig_session import GenerateSession
from ig_bot_functions import ClearFollowers, AddFollowers, CreateSafelist, deleteComments
@click.group()
def cli():
pass
def CheckPath(f):
"""
Decorator to check if the config file is a valid json/path.
"""
@functools.wraps(f)
def new_func(*args, **kwarg):
try:
if os.path.exists(kwarg['config']) and mimetypes.MimeTypes().guess_type(kwarg['config'])[0] == 'application/json':
return f(*args, **kwarg)
except:
pass
print('Config path could not be found')
return
return new_func
@cli.command(name="addFollowers")
@click.argument('config')
@click.argument('users', default=100, type=int)
@click.argument('target', default=None, type=str)
@CheckPath
def addUsers(config, users, target):
"""
Randomly adds users, can randomly add one from people *target
"""
AddFollowers(GenerateSession(config).Session, users, target)
@cli.command(name="createSafelist")
@click.argument('config')
@click.argument('path', default='safelist.json', type=str)
@CheckPath
def createSafelsit(config, path):
"""
Creates a safelist from the current people one is following
"""
CreateSafelist(GenerateSession(config).Session, path)
@cli.command(name="deleteFollowing")
@click.argument('config')
@click.argument('users', default=100, type=int)
@click.argument('safelist_path', default=None, type=str)
@CheckPath
def deleteUsers(config, users, safelist_path):
"""
Deletes people one is following, except those in the safelist if provided.
"""
safe_users = []
if safelist_path:
with open(safelist_path) as file:
safe_users = json.load(file)['safeUsers']
ClearFollowers(GenerateSession(config).Session, safe_users, users)
@cli.command(name="cleanComments")
@click.argument('config')
@click.argument('lastposts', default=1, type=int)
@CheckPath
def cleanComment(config, lastposts):
print('This feature is not yet complete.')
#deleteComments(GenerateSession(config).Session, [], lastposts)
if __name__ == "__main__":
cli()