forked from frite/twitter-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
99 lines (94 loc) · 3.21 KB
/
main.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
#!/usr/bin/env python
#
# Copyright 2014 Frite M.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import time
import datetime
import lib.twitterService as twitterService
import lib.dbService as db
import lib.alertsClass as alerts
'''initialization variable'''
global cKey
cKey=''
global cSecret
cSecret=''
global atKey
atKey=''
global atSecret
atSecret=''
global szName
szName=''
''' Check whether a user's profile is protected or not'''
def isProtected(user):
if user.protected is True:
oTextColor.warning("\tUser %s profile is protected"%user.screen_name)
return False
else:
return True
''' Fetch all tweets of a user '''
def getAllTweets(userObject):
now=datetime.datetime.now()
print "\t[*]\tGetting the tweets of %s at %s"%(userObject.screen_name,str(now))
tweets=twitter.getTweets(name=userObject.screen_name)
now=datetime.datetime.now()
print "\t[*]\tFinished getting the tweets of %s at %s"%(userObject.screen_name,str(now))
return tweets
''' Status message'''
def status():
oTextColor.header("\t\tIn God we trust, all others we monitor")
oTextColor.okblue(" ______ _ _ ")
oTextColor.okblue(" | ____| | | (_) ")
oTextColor.okblue(" | |__ _ _ _ __ | |__ ___ _ __ ___ _ __ _ ")
oTextColor.okblue(" | __|| | | | '_ \| '_ \ / _ \ '_ ` _ \| |/ _` |")
oTextColor.okblue(" | |___| |_| | |_) | | | | __/ | | | | | | (_| |")
oTextColor.okblue(" |______\__,_| .__/|_| |_|\___|_| |_| |_|_|\__,_|")
oTextColor.okblue(" | | ")
oTextColor.okblue(" |_| ")
oTextColor.okblue("\t[*]\tEuphemia twitter crawler v0.2\t[*]")
oTextColor.okblue("\t[*]\tDeveloped by frite\t\t[*]")
oTextColor.okgreen("\t[*]\tInitializing...\t\t\t[*]")
def fetchUser(username):
user=twitter.getUser(name=username)
db.storeUser(user)
if (isProtected(user)):
tweets=getAllTweets(user)
db.storeTweets(tweets,user)
followers=twitter.getFollowers(user)
db.storeFollowers(followers,user)
friends=twitter.getFriends(user.screen_name)
db.storeFriends(friends,user)
answer=raw_input('\tGet Another User (y/n):')
if(answer.lower()=='y'):
questionUser()
else:
return
'''ask the user'''
def questionUser():
userSeed=raw_input("\tInsert the user to fetch from:")
fetchUser(str(userSeed))
'''Main body of crawler '''
if __name__ == "__main__":
try:
global oTextColor
oTextColor=alerts.textAlert()
status()
global twitter
global db
twitter=twitterService.TwitterService(cKey,cSecret,atKey,atSecret,szName)
questionUser()
oTextColor.okgreen('\tExiting...')
oTextColor.endc('')
except (KeyboardInterrupt,SystemExit):
oTextColor.warning("\t[WARNING]\t Exiting...")
oTextColor.endc(' ')