-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_queue.py
580 lines (480 loc) · 19.8 KB
/
task_queue.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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
from celery import Celery
import os
import json
from crawler_handler import NewsCrawlerHandler, TwitterCrawlerHandler, InstaCrawlerHandler, GenericCrawlerHandler, RedditCrawlerHandler
from youtube_scrapper.utils import setDriver
from youtube_scrapper.channels import Channel
from youtube_scrapper import Video
from youtube_scrapper.utils import setDriver
from youtube_scrapper.trending import getTrends
import google_scrapper.trends.trends as googleTrends
import time
from data_handler import DataHandler ,LinkedDataHandler
from Feeder import Feeder ,SearchEngine
import uuid
import data_handler
from lively.actionsHandler import Actions
from facebook_scrapper.crawlBook.crawlers import users, pages, groups, search
from facebook_scrapper.crawlBook.utilities.sessionHandler import DriverSession
from linkedin_scrapper import ProfileScraper, CompanyScraper
from selenium.webdriver.chrome.options import Options
import tldextract
import whois
import json
import socket
from ipwhois import IPWhois
from celery.signals import celeryd_init
import serpscrap
import json
import re
from linkedin import linked
#------------------------------------------------------- App init ----------------------------------------------------------
app =Celery("tasks", backend='amqp', broker='amqp://')
#app =Celery("tasks", backend="amqp://" ,broker='pyamqp://mca_broker:rapidev@192.168.18.27/v_mca_broker')
COKIE="AQEDAS6tx2ACzBj1AAABbxfJiXQAAAFw0nROGlEAQE_aYJ8eicWyTAl_HJZlFC2DBYmtLe38Mwuzk5peiD0qUtwCwXhbudahOnLSROoq-AFTbnFGDfpawiUfi9-T5xgOh7hQrP11iTDovnCU4DLRdJom"
#-----------------------------------------------------------> Target Internet Survey --------------------------------------
@app.task()
def target_survey(keywords):
config = serpscrap.Config()
config_new = {
'cachedir': './KBM/cachedir',
'dir_screenshot': "./KBM/screenshots",
'clean_cache_after': 24,
'database_name': './KBM/db',
'do_caching': True,
'num_pages_for_keyword': 10,
'scrape_urls': True,
'search_engines': ['google', ],
'dir_screenshot': './KBM/screenshots',
'google_search_url': 'https://www.google.com/search?',
'executable_path': './chromedriver',
'screenshot': False,
'num_results_per_page': 10,
'num_pages_for_keyword':2
}
config.apply(config_new)
scrap = serpscrap.SerpScrap()
scrap.init(config=config.get(), keywords=keywords)
results = scrap.run()
return results
#-----------------------------------------------------------> FaceBook Crawler <--------------------------------------------
driver=None
def check_driver():
global driver
if driver is None:
driver = DriverSession(headless = True, login = True)
return driver
else:
return driver
@app.task()
def facebook_smart_search(username, entity_type):
data = search.smartSearch(check_driver(), entity_type, username = username)
print(data)
#data = {"id": data["id"], "full_name":data["name"], "profile_image_url":data["media_directory"]}
return data
@app.task()
def facebook_user(username, GTR, CTR):
data = users.User(check_driver(), username = username).getCompleteProfile(downloadPictures = True, downloadVideos=True)
dh=DataHandler(data={}, GTR=GTR, CTR=CTR)
dh.dump_json(root="/data/fb/")
@app.task()
def facebook_page(username, GTR, CTR):
data = pages.Page(check_driver(), username = username).getCompleteProfile(downloadPictures=True, downloadVideos=True)
dh=DataHandler(data={}, GTR=GTR, CTR=CTR)
dh.dump_json( root="/data/fb/")
@app.task()
def facebook_group(username, GTR, CTR):
data = groups.Group(check_driver(), username = username).getCompleteProfile(downloadPictures = True)
dh=DataHandler(data={}, GTR=GTR, CTR=CTR)
dh.dump_json( root="/data/fb/")
@app.task()
def facebook_search(query):
data = search.facebookSearch(check_driver(), query, "users")
return data
#------------------------------------------------------------- Generic Crawler ------------------------------------------------
def web_info(doamin):
domain = whois.query(doamin)
json_data=json.dumps(domain.__dict__, indent=4, default=str)
return json_data
def ip_info(domain_name):
ip_add=socket.gethostbyname(domain_name)
obj=IPWhois(ip_add)
results = obj.lookup_whois()
return results
@app.task()
def generic_crawler_taks(url="", GTR="", CTR="" , links=True,headings=True, paragraphs=True, pictures=False,videos=False, domain=False, ip=False):
print(url)
domain_=tldextract.extract(url)
domain_=domain_.registered_domain
handler=GenericCrawlerHandler(url=url, domain=domain_, links=links,headings=headings, paragraphs=paragraphs, pictures=pictures,videos=videos )
handler.run_crawler()
data={}
if ip:
ip_details=ip_info(domain_)
data["ip_information"]=ip_details
if domain:
domain_details=web_info(domain_)
data["domain_information"]=domain_details
dh=DataHandler(data=data, GTR=GTR, CTR=CTR)
dh.dump_json(root="/data/generic/")
#--------------------------------------------------------------- News -----------------------------------------------------------
@app.task()
def news_tasks(channel_name, number_of_headlines, GTR, CTR):
handler=NewsCrawlerHandler(news_name=channel_name , number_of_headlines=number_of_headlines, GTR=GTR, CTR=CTR)
handler.run_crawler()
@app.task()
def feed_tasks(GTR, CTR):
data={}
newsurls = {
'Google News':'https://news.google.com/news/rss/?hl=en&ned=us&gl=US',
'Yahoo News':'http://news.yahoo.com/rss/',
"Aljazeera":'https://www.aljazeera.com/xml/rss/all.xml',
"BBC World": 'http://feeds.bbci.co.uk/news/world/rss.xml',
"BuzzFeed": 'https://www.buzzfeed.com/world.xml',
"Blogs – E-International Relations":"https://www.e-ir.info/category/blogs/feed/",
"Global Issues News Headlines":"http://www.globalissues.org/news/feed",
"CNN":'http://rss.cnn.com/rss/edition_world.rss',
"Washington Post":"http://feeds.washingtonpost.com/rss/world",
"World news | The Guardian":"https://www.theguardian.com/world/rss",
"Times of India":'https://timesofindia.indiatimes.com/rssfeeds/296589292.cms'
}
for key,url in newsurls.items():
fed=Feeder(url=url)
data[key]=fed.getHeadlines()
dh=DataHandler(data)
dh.dump_json("feeds")
#----------------------------------------------------------------------- Twitter -----------------------------------------------
@app.task()
def twitter_user(username, GTR, CTR):
handler=TwitterCrawlerHandler(user=username, type_task="USER-C")
handler.run_crawler()
dh=data_handler.TweetDataHandler(username, CTR=CTR , GTR=GTR)
dh.send_profile_data()
@app.task()
def twitter_smart_search(username):
handler=TwitterCrawlerHandler(user=username, type_task="USER-S")
handler.run_crawler()
with open(f"./data/user/{username}.json", 'r') as json_data:
data = json.load(json_data)
data={"id": data["id"], "full_name":data["Full_name"],"profile_image_url":data["profile_image_url"]}
os.remove(f"./data/user/{username}.json")
return data
#-------------------------------------------from Home--------------------------------------------
from twisearch import twitterSearch
@app.task()
def twitter_search(query):
handler=TwitterCrawlerHandler(query=query, type_task="SEARCH")
handler.run_crawler()
result=Tweet_data()
return result
from os import listdir
from os.path import isfile, join
def Tweet_data():
currentdir=os.getcwd()
tweetfolder="./data/tweet"
all_tweets={}
num=0
tweetfiles = [f for f in listdir(tweetfolder) if isfile(join(tweetfolder, f))]
for x in tweetfiles:
with open(join(tweetfolder, x), 'r') as json_data:
data = json.load(json_data)
all_tweets[num]=data
num=num+1
os.remove(join(tweetfolder, x))
return all_tweets
@app.task()
def targetidentification(query):
data = twitterSearch(query=query)
return data
#--------------------------------------------------------------------- Trends -----------------------------------------------
@app.task()
def twitter_world_trends():
handler=TwitterCrawlerHandler(query="world", type_task="TRENDS")
handler.run_crawler()
@app.task()
def twitter_country_trends(country):
handler=TwitterCrawlerHandler(query=country, type_task="TRENDS")
handler.run_crawler()
#------------------------------------------------------------------ LinkedIn -----------------------------------------------------
@app.task()
def linkedin_user(username, GTR, CTR):
options = Options()
options.add_argument('--headless')
with ProfileScraper(cookie=COKIE) as scraper:
profile = scraper.scrape(user=username)
data=profile.to_dict()
dh=LinkedDataHandler(data ,CTR=CTR, GTR=GTR)
dh.dump_json()
@app.task()
def linkedin_company(username, GTR, CTR):
options = Options()
options.add_argument('--headless')
with CompanyScraper(cookie=COKIE) as scraper:
profile = scraper.scrape(username)
data=profile.to_dict()
dh=LinkedDataHandler(data ,CTR=CTR, GTR=GTR)
dh.dump_json(company=True)
@app.task()
def linkedin_smart_search(username):
options = Options()
#options.add_argument('--headless')
with ProfileScraper(cookie=COKIE, driver_options=options) as scraper:
profile = scraper.scrape(user=username)
data=profile.to_dict()
print(data)
dh=LinkedDataHandler(data )
data=dh.send_image_ss()
return data
@app.task()
def linkedin_search(query):
print(query)
driver = linked.setDriver(executable_path = "./chromedriver")
data=linked.search(driver, query, entityType = "people", depth = 2)
return data
#--------------------------------------------------------------------- Instagram ----------------------------------------------------
@app.task()
def insta_user(username, category, GTR, CTR):
handler=InstaCrawlerHandler(username=username, CTR=CTR, GTR=GTR, category=category)
handler.run_crawler()
@app.task()
def insta_smart_search(username):
handler=InstaCrawlerHandler(username=username, category="AUTHOR", smart_flag=True)
handler.run_crawler()
path=os.getcwd()+"/data/insta/sm.json"
try:
with open(path, 'r') as f:
data=json.load(f)
data={"id": data["graphql"]["user"]["id"], "full_name":data["graphql"]["user"]["full_name"],"profile_image_url":data["graphql"]["user"]["profile_pic_url_hd"]}
return data
except Exception as e:
print(e)
finally:
os.remove(path)
@app.task()
def instagram_search(query):
handler=InstaCrawlerHandler(search_keyword=query )
handler.run_crawler()
path=os.getcwd()+f"/data/insta/{query}.json"
try:
with open(path, 'r') as f:
data=json.load(f)
return data
except Exception as e:
print(e)
finally:
os.remove(path)
#-----------------------------------------------------------------------Reddit--------------------------------------------------
#-----------------------------------------------------------------------Reddit--------------------------------------------------
from rScraper.rScraper import popularPosts
from rScraper.rScraper import subreddit
from rScraper.rScraper import user
from rScraper import rScraper
@app.task()
def reddit_trends(trends_filter, top_time):
# handler=RedditCrawlerHandler(trends_filter=trends_filter, top_time=top_time, spider="TRENDS")
# handler.run_crawler()
data = popularPosts(category = trends_filter, timePeriod = "All Time")
data={"trends": data}
dh=data_handler.TargetDataHandler(data=data, target_type="reddit_trends")
dh.send_data()
@app.task()
def reddit_subreddit(username, GTR, CTR):
data = subreddit(subreddit = username, category = "hot")
dh=DataHandler(data=data, GTR=GTR, CTR=CTR)
dh.send_data()
# handler=RedditCrawlerHandler(username=username, CTR=CTR, GTR=GTR, spider="SUBREDDIT")
# handler.run_crawler()
@app.task()
def reddit_user(username, GTR, CTR):
# handler=RedditCrawlerHandler(username=username, CTR=CTR, GTR=GTR, spider="USER")
# handler.run_crawler()
data= user(username = username, category = "top", timePeriod = "This Month")
dh=DataHandler(data=data, GTR=GTR, CTR=CTR)
dh.send_data()
#------------------------------------------------FROM hoME
@app.task()
def User_reddit_search(username):
# handler=RedditCrawlerHandler(username=username, spider="SUBREDDIT_SEARCH")
# handler.run_crawler()
# path=os.getcwd()+"/data/reddit/data.json"
# try:
# with open(path, 'r') as f:
# data=json.load(f)
# return data
# except Exception as e:
# print(e)
# finally:
# os.remove(path)
results = rScraper.search(username, entityType = "communities")
return results
## other variant
## results = search("westworld", entityType = "posts")
@app.task()
def Subreddit_reddit_search(username):
# handler=RedditCrawlerHandler(username=username, spider="USER_SEARCH")
# handler.run_crawler()
# path=os.getcwd()+"/data/reddit/data.json"
# try:
# with open(path, 'r') as f:
# data=json.load(f)
# return data
# except Exception as e:
# print(e)
# finally:
# os.remove(path)
results = rScraper.search(username, entityType = "posts")
return results
#--------------------------------------------------------- youtube -------------------------------------------------------
@app.task()
def youtube_target(channel_id='', GTR="", CTR=""):
# set driver and url
driver = setDriver(executable_path = './chromedriver', headless = True, maximize = True)
url = f"https://www.youtube.com/channel/{channel_id}"
# start scraping
data = Channel(driver, url = url).getCompleteProfile()
for videos in data["videos"]["new"]:
match=re.search(r"youtube\.com/.*v=([^&]*)", videos["link"])
if match:
id=match.group(1)
video_data=Video.video_scrapper(driver,id)
print(id)
data[id]=video_data
driver.close()
dh=DataHandler(data=data, GTR=GTR, CTR=CTR)
dh.send_data()
@app.task()
def youtube_trends():
driver = setDriver(executable_path = './chromedriver', headless = True, maximize = True)
data = getTrends(driver)
driver.close()
data={"trends": data}
dh=data_handler.TargetDataHandler(data=data, target_type="youtube_trends")
dh.send_data()
#-------------------------------------------------keybase management system----------------------------------------------
@app.task()
def keybase_system(payload):
keywords=payload["keywords"]
print(keywords)
CTR=payload["CTR"]
GTR=payload["GTR"]
config = serpscrap.Config()
config_new = {
'cachedir': './KBM/cachedir',
'dir_screenshot': "./KBM/screenshots",
'clean_cache_after': 24,
'database_name': './KBM/db',
'do_caching': True,
'num_pages_for_keyword': 10,
'scrape_urls': True,
'search_engines': ['google', ],
'dir_screenshot': './KBM/screenshots',
'google_search_url': 'https://www.google.com/search?',
'executable_path': './chromedriver',
'screenshot': False,
'num_results_per_page': 10,
'num_pages_for_keyword':2
}
config.apply(config_new)
scrap = serpscrap.SerpScrap()
scrap.init(config=config.get(), keywords=keywords)
results = scrap.run()
data={"data":results}
dh=DataHandler(data=data, GTR=GTR, CTR=CTR)
dh.send_data()
@app.task()
def google_trends_daily(country):
chromeDirectory = "./chromedriver"
driver = googleTrends.setDriver(chromeDirectory, headless = True)
# for daily
dailytrends=googleTrends.getDailySearchTrends(driver, country = country)
data={"trends": dailytrends}
driver.close()
dh=data_handler.TargetDataHandler(data=data, target_type="google_trends")
dh.send_data()
@app.task()
def google_trends_realtime(country):
chromeDirectory = "./chromedriver"
driver = googleTrends.setDriver(chromeDirectory, headless = True)
# for realtime results
trends=googleTrends.getRealtimeTrends(driver, country = country, category = "all")
driver.close()
data={"trends": trends}
dh=data_handler.TargetDataHandler(data=data, target_type="google_trends")
dh.send_data()
#--------------------------------------------------------------------- Twitter Searching Tools --------------------------------
#----------------------------------------------------------------- Avatar API End point ------------------------------------
#---------------------------------------------------------------- Post ---------------------------------------------------
@app.task()
def avtar_post(data):
loginCredentials={
"email":data["email"],
"password":data["password"]}
act = Actions(site = data["social_media"],loginCredentials=loginCredentials, submit = False)
act.post(text = data["text"], media = data["media"])
#---------------------------------------------------------------- comment ---------------------------------------------------
@app.task()
def avtar_comment(data):
loginCredentials={
"email":data["email"],
"password":data["password"]}
print(data)
act = Actions(site = data["social_media"], loginCredentials=loginCredentials, submit = False)
act.comment(post_link = data["target_post"], text = data["text"])
#---------------------------------------------------------------- Reaction ---------------------------------------------------
@app.task()
def avtar_Reaction(data):
loginCredentials={data["social_media"]:{
"email":data["email"],
"password":data["password"]}}
act = Actions(site = data["social_media"], loginCredentials=loginCredentials, submit = False)
act.react(post_link= data["target_post"], reaction = data["reaction"])
#---------------------------------------------------------------- share ---------------------------------------------------
@app.task()
def avatar_share(data):
loginCredentials={data["social_media"]:{
"email":data["email"],
"password":data["password"]}}
act = Actions(site = data["social_media"], loginCredentials=loginCredentials, submit = False)
act.share(post_link= data["target_post"], sub_text =data["text"])
#-------------------------------------------------------- tools ---------------------------------------------------------------
from di_ekaf.fake import generate_fake_id
from acad_patents.academics_and_patents import scholar
from darker.dark_search import DarkSearch
from acad_patents.academics_and_patents import patents
from ip_logger.logger import IpLogger
from res.image_search import reverse_search
@app.task()
def fake_person_generator( nationality, gender, age):
result = generate_fake_id(name_set = nationality, country = nationality, gender = gender, age = age)
return result
@app.task()
def darkweb(query=""):
results = DarkSearch(timeout = 8).searchDarkWeb(query)
return results
@app.task()
def scholar_(query=""):
results = scholar(query)
return results
@app.task()
def patents_(query=""):
results = patents(query)
return results
import requests
@app.task()
def ip_shortend_url(url=""):
#log = IpLogger(headless = True, timeout = 10)
#result=log.create_payload(url)
#log.log_driver.close()
result=requests.post("http://majidahmed.pythonanywhere.com/create", data = {'url': url})
return result.json()
@app.task()
def ip_tracking(code="", start_date="", end_date="", GTR="", CTR=""):
#log = IpLogger(headless = True, timeout = 10)
#data=log.track_code(code = code, start_date = start_date, end_date = end_date)
#log.log_driver.close()
result=requests.get(f"http://majidahmed.pythonanywhere.com/track/{code}")
return result.json()
@app.task()
def image_rever_lookup(url=""):
results = reverse_search(url = url)
return results