-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMain.py
57 lines (48 loc) · 1.93 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
from bs4 import BeautifulSoup as Soup
from Auth import AuthHandler
from UserDetails import UserDetails
from DataExtraction import DataExtractor
from Utils import UrlBuilder
import sys, random
reload(sys)
sys.setdefaultencoding("utf-8")
testEnv = False if len(sys.argv) < 2 else True
authHandlerObject = AuthHandler.getAuthHandlerObject()
if not testEnv:
authHandlerObject.authenticateUser()
opener = authHandlerObject.getUrlOpener()
urlBuilderObject = UrlBuilder.UrlBuilder()
def testGetHtmlAsTextForGivenUrl(url):
if "rhythmpathak" in url:
with open("TestData/test.html", "r") as reader:
return reader.read()
with open("TestData/test1.html", "r") as reader:
return reader.read()
def getHtmlAsTextForGivenUrl(url):
if (testEnv):
return testGetHtmlAsTextForGivenUrl(url)
response = opener.open(url)
return response.read()
def getDetailsAboutGivenUser(id):
url = urlBuilderObject.buildUrlForAboutSection(id)
Page_Html = getHtmlAsTextForGivenUrl(url)
newUser = UserDetails.UserDetails(Page_Html)
return newUser.getAllUserData()
def getAllFriendsOfGivenUser(id):
url = urlBuilderObject.buildUrlForFriendListSection(id)
tempUserFriends = UserDetails.UserFriendList()
while url:
Page_Html = getHtmlAsTextForGivenUrl(url)
tempUserFriends.setRawHtmlTextData(Page_Html)
tempUserFriends.extractFriendList()
url = tempUserFriends.getUrlForSeeMoreFriends()
return tempUserFriends.getFriendList()
def runTest():
print getDetailsAboutGivenUser({'isCustomUrl': True, 'userId': u'rhythmpathak'})
print getAllFriendsOfGivenUser({'isCustomUrl': True, 'userId': u'rhythmp'})
if __name__ == "__main__":
if testEnv:
runTest()
else:
print getDetailsAboutGivenUser({'isCustomUrl': True, 'userId': u'narendra.pandey.9480'})
print getAllFriendsOfGivenUser({'isCustomUrl': True, 'userId': u'narendra.pandey.9480'})