-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
163 lines (130 loc) · 5.16 KB
/
app.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
import re
import requests
from config import LINKEDIN_TOKEN
from flask_cors import CORS
from flask import Flask, render_template, jsonify, request
from linkedin import linkedin
from linkedin_queries import linkedin_api
from srcs.bing_search_api import get_entities_from_search
from srcs.bing_search_api import scrape_contact_from_url
from bs4 import BeautifulSoup as bs
app = Flask(__name__, static_url_path='')
CORS(app)
@app.route('/')
def showMachineList():
return render_template('iws.html')
# Linkedin access token
# You can use this token for testing purposes
# to get a new code, please refer to
# https://developer.linkedin.com/docs/v2/oauth2-client-credentials-flow
application = linkedin.LinkedInApplication(LINKEDIN_TOKEN)
# Query fields: https://developer.linkedin.com/docs/fields/company-profile
def get_query(keywords):
return application.search_company(
selectors=[
{
'companies': [
'name',
'universal-name',
'website-url',
'description',
'square-logo-url',
'specialties',
'locations']}],
params={
'keywords': keywords,
'facet': 'location,us:84'})
query_data = []
# Api to get the main data from linkedin
@app.route('/iws/api/v1.0/companies', methods=['POST'])
def get_tasks():
global query_data
query_data = linkedin_api(
request.get_json()["search"],
request.get_json()["page"] * 20,
20)
return jsonify(query_data)
# Look for related data of the company from the web using google
@app.route('/companies/<string:name>', methods=['GET'])
def get_company(name):
comp = [query for query in query_data["data"]
if query['universalName'] == name]
bzData = getBuzzInfo(
comp[0]["name"],
comp[0]["locations"]["values"][0]["address"]["postalCode"])
comp[0]["websiteUrl"] = (
"http://" + comp[0]["websiteUrl"],
comp[0]["websiteUrl"])[
comp[0]["websiteUrl"].startswith('http')]
domain = re.split(
'^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)',
comp[0]["websiteUrl"].lower())[1]
# If you'd like to use the Deep Learning NER model to attempt to
# grab named entities then you can pass 'get_entities=True'
# into scrape_contact_from_url. It'll load the model and tensorflow,
# return num, emails, links, entities, extras
# The model needs to be trained more and it runs slowly so it's off by
# default
num, emails, links, _, extras = scrape_contact_from_url(
domain, get_entities=False)
bingData = {}
bingData['sources'] = []
# get social media data and links from Bing
for link in links:
if 'facebook' in link:
bingData['facebook'] = link
elif 'twitter' in link:
bingData['twitter'] = link
elif 'linkedin' in link:
bingData['linkedin'] = link
else:
bingData['sources'].append(link)
# You can uncomment this code if you want more information regarding to the contact person
# it's commented right now because of performance purposes:
# if (bzData and bzData.contactPerson):
# bingData['person'] = get_entities_from_search(bzData.contactPerson)
return render_template(
'detail.html',
compData=comp[0],
buzzData=bzData,
bingData=bingData)
# look for data on buzzfile page http://www.buzzfile.com/
def getBuzzInfo(name, postalCode):
data = {}
link = 'http://www.buzzfile.com/Search/Company/Results?searchTerm=' + \
name + '¶meter=zipcode--' + postalCode + '&type=1'
html = requests.get(link)
soup = bs(html.text, "lxml")
if (len(soup.select(
'#companyList tr:nth-of-type(3) td:nth-of-type(2) a')) == 0):
return 0
else:
searchResult = (
soup.select(
'#companyList tr:nth-of-type(3) td:nth-of-type(2) a')[0]['href'])
data['src'] = 'http://www.buzzfile.com' + searchResult
cpage = requests.get(data['src'])
soup = bs(cpage.text, "lxml")
contactInfo = soup.select(
'.company-info-box .company-info-box-title + .panel-collapse')[0]
data['address'] = contactInfo.select(
'[itemprop="address"]')[0].text.strip()
data['contactPerson'] = contactInfo.select(
'[itemprop="employee"]')[0].text.strip()
data['contactTitle'] = contactInfo.select(
'[itemprop="contactType"]')[0].text.strip()
data['contactPhone'] = contactInfo.select(
'[itemprop="telephone"]')[0].text.strip()
bsInfo = soup.select(
'.company-info-box .company-info-box-title + .panel-collapse')[2]
data['bsDesc'] = bsInfo.select('[itemprop="description"]')[0].text.strip()
foundedYear = soup.select(
'.company-info-box-left .company-info-header span')
data['fYear'] = foundedYear[0].text.strip()
bsinfo2 = soup.select('.company-info-box .my-table-td-header + td a')
data['sector'] = bsinfo2[0].text.strip()
data['category'] = bsinfo2[1].text.strip()
data['industry'] = bsinfo2[2].text.strip()
return data
if __name__ == "__main__":
app.run()