-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
atac.py
executable file
·558 lines (511 loc) · 21.1 KB
/
atac.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
from atac.util.Util import str2bool, get_file_content
import argparse
import os
import sys
from threading import Thread
import atac
def get_config_arguments(arguments):
"""
Generate New Config
Parameters
----------
name : str
The name of the animal
sound : str
The sound the animal makes
num_legs : int, optional
The number of legs the animal (default is 4)
"""
encrypted_config = False
key_file_path = None
config_file_path = "auth.json"
#
if arguments.encrypted_config is not None:
encrypted_config = str2bool(getattr(arguments, "encrypted_config"))
print("{} {}", encrypted_config, type(encrypted_config))
#
if arguments.config_file is not None:
config_file_path = getattr(arguments, "config_file")
print("{} {}", config_file_path, type(config_file_path))
#
if arguments.key_file is not None:
key_file_path = getattr(arguments, "key_file")
#
return encrypted_config, config_file_path, key_file_path
# sub-command functions
def configuration(arguments):
"""
Generate New Config
Parameters
----------
name : str
The name of the animal
sound : str
The sound the animal makes
num_legs : int, optional
The number of legs the animal (default is 4)
"""
encrypted_config, config_file_path, key_file_path = get_config_arguments(arguments)
config = atac.Config(encrypted_config, config_file_path, key_file_path)
#
if arguments.generate_key_file is not None:
generate_key_file_path = getattr(arguments, "generate_key_file")
if generate_key_file_path:
config.generate_key()
config.save_key(generate_key_file_path)
#
if arguments.new_config_file is not None:
new_config_file_path = getattr(arguments, "new_config_file")
if new_config_file_path:
config.new_config(new_config_file_path)
#
if arguments.decrypted_config_file is not None:
decrypted_config_file_path = getattr(arguments, "decrypted_config_file")
if decrypted_config_file_path:
config.load_config()
config.save_config(decrypted_config_file_path, False)
# sub-command functions
def chat(arguments):
"""
Generate New Config
Parameters
----------
name : str
The name of the animal
sound : str
The sound the animal makes
num_legs : int, optional
The number of legs the animal (default is 4)
"""
encrypted_config, config_file_path, key_file_path = get_config_arguments(arguments)
chat = atac.SendChat(encrypted_config, config_file_path, key_file_path)
# sub-command functions
def irc(arguments):
"""
Generate New Config
Parameters
----------
name : str
The name of the animal
sound : str
The sound the animal makes
num_legs : int, optional
The number of legs the animal (default is 4)
"""
encrypted_config, config_file_path, key_file_path = get_config_arguments(arguments)
chat = atac.SendIRC(encrypted_config, config_file_path, key_file_path)
#
if arguments.list_users is not None:
list_users = getattr(arguments, "list_users")
if arguments.message_users is not None:
message_users = getattr(arguments, "message_users")
if arguments.message_channels is not None:
message_channels = getattr(arguments, "message_channels")
#
chat.list_channels()
# sub-command functions
def email(arguments):
"""
Generate New Config
Parameters
----------
name : str
The name of the animal
sound : str
The sound the animal makes
num_legs : int, optional
The number of legs the animal (default is 4)
"""
encrypted_config, config_file_path, key_file_path = get_config_arguments(arguments)
emailer = atac.SendEmail(encrypted_config, config_file_path, key_file_path)
subject = None
email_files_path = os.path.dirname(os.path.abspath(__file__)) + "/data/contacts/emails/"
#
if arguments.subject is not None:
subject = getattr(arguments, "subject")
if arguments.message_file is not None:
message_file_path = getattr(arguments, "message_file")
if arguments.emails_file is not None:
email_files_path = getattr(arguments, "emails_file")
if arguments.target is not None:
target = getattr(arguments, "target")
#
_, content = emailer.get_config()
#
if not subject:
sys.exit(1)
#
if not message_file_path:
sys.exit(1)
#
emailer.send_batch(
email_files_path,
message_file_path,
subject,
False,
False,
correct_spelling=False,
src=False,
dest=False,
)
# sub-command functions
def phone(arguments):
"""
Generate New Config
Parameters
----------
name : str
The name of the animal
sound : str
The sound the animal makes
num_legs : int, optional
The number of legs the animal (default is 4)
"""
encrypted_config, config_file_path, key_file_path = get_config_arguments(arguments)
chatter = atac.SendChat(encrypted_config, config_file_path, key_file_path)
#
target = "whatsapp"
phone_files_path = os.path.dirname(os.path.abspath(__file__)) + "/data/contacts/phones/"
#
if arguments.message_file is not None:
message_file_path = getattr(arguments, "message_file")
if arguments.phones_file is not None:
phone_files_path = getattr(arguments, "phones_file")
if arguments.target is not None:
target = getattr(arguments, "target")
#
if "whatsapp" in target and os.environ.get("DISPLAY"):
chatter.send_pywhatkit(phone_files_path, message_file_path)
# sub-command functions
def art(arguments):
"""
Generate New Config
Parameters
----------
name : str
The name of the animal
sound : str
The sound the animal makes
num_legs : int, optional
The number of legs the animal (default is 4)
"""
encrypted_config, config_file_path, key_file_path = get_config_arguments(arguments)
artist = atac.Art(encrypted_config, config_file_path, key_file_path)
font_size = 22
message_text = None
images_path = None
gif_path = None
#
if arguments.font_size is not None:
font_size = int(getattr(arguments, "font_size"))
if arguments.message_text is not None:
message_text = getattr(arguments, "message_text")
if arguments.images_path is not None:
images_path = getattr(arguments, "images_path")
if arguments.gif_path is not None:
gif_path = getattr(arguments, "gif_path")
#
if images_path:
artist.generate_gifs_from_all_dirs(images_path, "*.png")
#
if gif_path and message_text:
artist.add_centered_text_to_gif(gif_path, message_text, font_size)
# sub-command functions
def social(arguments):
"""
Generate New Config
Parameters
----------
name : str
The name of the animal
sound : str
The sound the animal makes
num_legs : int, optional
The number of legs the animal (default is 4)
"""
encrypted_config, config_file_path, key_file_path = get_config_arguments(arguments)
socialite = atac.SendSocial(encrypted_config, config_file_path, key_file_path)
#
target = "twitter"
#
if arguments.message_file is not None:
message_file_path = getattr(arguments, "message_file")
if arguments.target is not None:
target = getattr(arguments, "target")
#
if "facebook" in target:
socialite.send_facebook(message_file_path)
if "twitter" in target:
socialite.send_twitter(message_file_path)
def scrape(arguments):
"""
Generate New Config
Parameters
----------
name : str
The name of the animal
sound : str
The sound the animal makes
num_legs : int, optional
The number of legs the animal (default is 4)
"""
encrypted_config, config_file_path, key_file_path = get_config_arguments(arguments)
#
url = ""
target = ""
#
if arguments.url is not None:
url = getattr(arguments, "url")
scraper = atac.Scrape(encrypted_config, config_file_path, key_file_path)
scraper.process_page("url", url)
elif arguments.target is not None:
target = getattr(arguments, "target")
scraper = atac.Scrape(encrypted_config, config_file_path, key_file_path)
scraper.process_page(target, scraper.scrape["targets"][target])
else:
# create threads
scrapers = {}
config = atac.Config(encrypted_config, config_file_path, key_file_path)
for data_key, starting_url in config.data["scrape"]["targets"].items():
print("{0} - {1}".format(data_key, starting_url))
scrapers[data_key] = atac.Scrape(encrypted_config, config_file_path, key_file_path)
catcher_thread = Thread(target=scrapers[data_key].process_page, args=(data_key, starting_url))
catcher_thread.start()
def compose(arguments):
"""
Generate New Config
Parameters
----------
name : str
The name of the animal
sound : str
The sound the animal makes
num_legs : int, optional
The number of legs the animal (default is 4)
"""
corpus_file_path = os.path.dirname(os.path.abspath(__file__)) + "/data/pg1009.txt"
#
input_file_path = None
output_file_path = None
translate_from_languagecode = None
translate_to_languagecode = None
paraphrase_language = None
spellcheck_language = None
images_dir = None
#
if arguments.images_dir is not None:
images_dir = getattr(arguments, "images_dir")
if arguments.input_file_path is not None:
input_file_path = getattr(arguments, "input_file_path")
if arguments.output_file_path is not None:
output_file_path = getattr(arguments, "output_file_path")
if arguments.translate_from_languagecode is not None:
translate_from_languagecode = getattr(arguments, "translate_from_languagecode")
if arguments.translate_to_languagecode is not None:
translate_to_languagecode = getattr(arguments, "translate_to_languagecode")
if arguments.paraphrase_language is not None:
paraphrase_language = getattr(arguments, "paraphrase_language")
if arguments.spellcheck_language is not None:
spellcheck_language = getattr(arguments, "spellcheck_language")
#
paraphrase = paraphrase_language if paraphrase_language else False
from_lang = translate_from_languagecode if translate_from_languagecode else "en"
to_lang = translate_to_languagecode if translate_to_languagecode else "en"
translate = True if from_lang != to_lang else False
spellcheck = spellcheck_language if spellcheck_language else False
#
encrypted_config, config_file_path, key_file_path = get_config_arguments(arguments)
composer = atac.Compose(encrypted_config, config_file_path, key_file_path)
#
corpus = None
if input_file_path is not None:
corpus = get_file_content(input_file_path)
if corpus is not None:
transform = composer.transform(corpus, paraphrase, translate, spellcheck, src=from_lang, dest=to_lang)
try:
if not os.path.isdir(os.path.dirname(output_file_path)):
os.makedirs(os.path.dirname(output_file_path))
with open(output_file_path, mode="w") as output_file:
output_file.write("\n".join(transform))
except Exception as err:
print(err)
def clean(arguments):
"""
Generate New Config
Parameters
----------
name : str
The name of the animal
sound : str
The sound the animal makes
num_legs : int, optional
The number of legs the animal (default is 4)
"""
encrypted_config, config_file_path, key_file_path = get_config_arguments(arguments)
cleaner = atac.Clean(encrypted_config, config_file_path, key_file_path)
#
email_files_path = os.path.dirname(os.path.abspath(__file__)) + "/data/contacts/emails/"
phone_files_path = os.path.dirname(os.path.abspath(__file__)) + "/data/contacts/phones/"
#
if arguments.target is not None:
target = getattr(arguments, "target")
#
if "email" in target:
cleaner.clean_emails(email_files_path)
if "phone" in target:
cleaner.clean_phones(phone_files_path)
else:
cleaner.clean_emails(email_files_path)
cleaner.clean_phones(phone_files_path)
if __name__ == "__main__":
# create the top-level parser
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
# create the parser for the "config" command
parser_config = subparsers.add_parser("config")
parser_config.add_argument("-c", dest="config_file", type=str, help="use config file path")
parser_config.add_argument("-e", dest="encrypted_config", action="store_true")
parser_config.add_argument("-k", dest="key_file", type=str, help="use key file path")
parser_config.add_argument("-g", dest="generate_key_file", type=str, help="generate new key file path")
parser_config.add_argument(
"-d",
dest="decrypted_config_file",
type=str,
help="output decrypted config file path",
)
parser_config.add_argument("-n", dest="new_config_file", type=str, help="generate new config file path")
parser_config.set_defaults(func=configuration)
# create the parser for the "email command
parser_email = subparsers.add_parser("email")
parser_email.add_argument("-c", dest="config_file", type=str, help="use config file path")
parser_email.add_argument("-e", dest="encrypted_config", action="store_true")
parser_email.add_argument("-k", dest="key_file", type=str, help="use key file path")
parser_email.add_argument("-m", dest="message_file", type=str, help="path to message file")
parser_email.add_argument("-p", dest="emails_file", type=str, help="path to csv dir or file")
parser_email.add_argument("-s", dest="subject", type=str, help="email subject")
parser_email.add_argument("-t", dest="target", choices=["smtp", "aws"], default="smtp")
parser_email.add_argument("-v", dest="verbose")
parser_email.set_defaults(func=email)
# create the parser for the irc command
parser_irc = subparsers.add_parser("irc")
parser_irc.add_argument("-c", dest="config_file", type=str, help="use config file path")
parser_irc.add_argument("-e", dest="encrypted_config", action="store_true")
parser_irc.add_argument("-k", dest="key_file", type=str, help="use key file path")
parser_irc.add_argument("-u", dest="message_users", action="store_true")
parser_irc.add_argument("-z", dest="message_channels", action="store_true")
parser_irc.add_argument("-l", dest="list_users", action="store_true")
parser_irc.add_argument("-v", dest="verbose")
parser_irc.set_defaults(func=irc)
# create the parser for the chat command
parser_email = subparsers.add_parser("chat")
parser_email.add_argument("-c", dest="config_file", type=str, help="use config file path")
parser_email.add_argument("-e", dest="encrypted_config", action="store_true")
parser_email.add_argument("-k", dest="key_file", type=str, help="use key file path")
parser_email.add_argument("-u", dest="message_users", action="store_true")
parser_email.add_argument("-l", dest="list_users", action="store_true")
parser_email.add_argument("-v", dest="verbose")
parser_email.set_defaults(func=chat)
# create the parser for the "phone" command
parser_phone = subparsers.add_parser("phone")
parser_phone.add_argument("-c", dest="config_file", type=str, help="use config file path")
parser_phone.add_argument("-e", dest="encrypted_config", action="store_true")
parser_phone.add_argument("-k", dest="key_file", type=str, help="use key file path")
parser_phone.add_argument("-m", dest="message_file", type=str, help="path to message file")
parser_phone.add_argument("-p", dest="phones_file", type=str, help="path to csv dir or file")
parser_phone.add_argument("-t", dest="target", choices=["whatsapp", "sms"])
parser_phone.add_argument("-w", dest="whatsapp", choices=["pywhatkit", "twilio", "yowsup"])
parser_phone.add_argument("-s", dest="sms", choices=["aws", "twilio"], default="aws")
parser_phone.add_argument("-v", dest="verbose")
parser_phone.set_defaults(func=phone)
# create the parser for the "social" command
parser_social = subparsers.add_parser("social")
parser_social.add_argument("-c", dest="config_file", type=str, help="use config file path")
parser_social.add_argument("-e", dest="encrypted_config", action="store_true")
parser_social.add_argument("-k", dest="key_file", type=str, help="use key file path")
parser_social.add_argument("-m", dest="message", type=str, help="path to message file")
parser_social.add_argument("-t", dest="target", choices=["facebook", "twitter"], default="twitter")
parser_social.add_argument("-v", dest="verbose")
parser_social.set_defaults(func=social)
# create the parser for the "art" command
parser_art = subparsers.add_parser("art")
parser_art.add_argument("-c", dest="config_file", type=str, help="use config file path")
parser_art.add_argument("-e", dest="encrypted_config", action="store_true")
parser_art.add_argument("-k", dest="key_file", type=str, help="use key file path")
parser_art.add_argument("-f", dest="font_size", type=int, help="font_size")
parser_art.add_argument("-m", dest="message_text", type=str, help="text message")
parser_art.add_argument("-g", dest="gif_path", type=str, help="path to gif file")
parser_art.add_argument("-p", dest="images_path", type=str, help="path to images directory")
parser_art.add_argument("-t", dest="art_type", choices=["sudoku", "invaders"])
parser_art.add_argument("-v", dest="verbose")
parser_art.set_defaults(func=art)
# create the parser for the "scrape" command
parser_scrape = subparsers.add_parser("scrape")
parser_scrape.add_argument("-c", dest="config_file", type=str, help="use config file path")
parser_scrape.add_argument("-e", dest="encrypted_config", action="store_true")
parser_scrape.add_argument("-k", dest="key_file", type=str, help="use key file path")
parser_scrape.add_argument(
"-t",
dest="target",
choices=[
"museums",
"embassies",
"activism",
"education",
"religion",
"rescue",
"addiction",
"music",
"journalists",
"defense",
"ukraine",
"islam",
"all",
],
default="all",
)
parser_scrape.add_argument("-u", dest="url", help="The URL to scrape.")
parser_scrape.add_argument("-v", dest="verbose")
parser_scrape.set_defaults(func=scrape)
# create the parser for the "compose" command
parser_compose = subparsers.add_parser("compose")
parser_compose.add_argument("-c", dest="config_file", type=str, help="use config file path")
parser_compose.add_argument("-e", dest="encrypted_config", action="store_true")
parser_compose.add_argument("-g", dest="images_dir", type=str, help="images directory to create gif from")
parser_compose.add_argument("-k", dest="key_file", type=str, help="use key file path")
parser_compose.add_argument("-i", dest="input_file_path", type=str, required=False, help="input_file_path")
parser_compose.add_argument("-o", dest="output_file_path", type=str, required=False, help="output_file_path")
parser_compose.add_argument("-p", dest="paraphrase_language", type=str, help="paraphrase source language")
parser_compose.add_argument("-s", dest="spellcheck_language", type=str, help="spellcheck source language")
parser_compose.add_argument(
"-f",
dest="translate_from_languagecode",
type=str,
help="translate from source language code",
)
parser_compose.add_argument(
"-t",
dest="translate_to_languagecode",
type=str,
help="translate to target language code",
)
parser_compose.add_argument("-v", dest="verbose")
parser_compose.set_defaults(func=compose)
# create the parser for the "compose" command
parser_clean = subparsers.add_parser("clean")
parser_clean.add_argument("-c", dest="config_file", type=str, help="config file")
parser_clean.add_argument("-e", dest="encrypted_config", action="store_true")
parser_clean.add_argument("-k", dest="key_file", type=str, help="key file path")
parser_clean.add_argument("-t", dest="target", choices=["email", "phone", "all"])
parser_clean.add_argument("-v", dest="verbose")
parser_clean.set_defaults(func=clean)
# parse the args and call whatever function was selected
args = parser.parse_args()
# validate conditions
cond_translation_from = "translate_from_languagecode" in vars(args) and "translate_to_languagecode" not in vars(
args
)
cond_translation_to = "translate_to_languagecode" in vars(args) and "translate_from_languagecode" not in vars(args)
if cond_translation_from or cond_translation_to:
parser.error("The -LoadFiles argument requires the -SourceFolder or -SourceFile")
#
args.func(args)