Advertisement
tmthyjames

Untitled

Oct 24th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. import flask, flask.views
  2. from flask import request
  3. import os
  4. import requests
  5. from bs4 import BeautifulSoup
  6. import re
  7.  
  8. app = flask.Flask(__name__)
  9.  
  10.  
  11. class View(flask.views.MethodView):
  12.  
  13. def get(self):
  14. return flask.render_template('index.html')
  15.  
  16. def getPhone(n):
  17. n=0
  18. while n<6:
  19. if re.search(regNum,contactData[n].text) and re.search(regAddr,contactData[n].text):
  20. number = contactData[n].text
  21. flask.flash(firmName)
  22. flask.flash(jobTitle)
  23. flask.flash(jobCity)
  24. flask.flash(number)
  25. break
  26. elif re.search(regNum,contactData[n].text):
  27. number = contactData[n].text
  28. flask.flash(firmName)
  29. flask.flash(jobTitle)
  30. flask.flash(jobCity)
  31. flask.flash(number)
  32. break
  33. elif re.search(regNum,moreSoup.find_all('span',{'class':'nowrap'})[n].text):
  34. number = soup.find_all('span',{'class':'nowrap'})[n].text
  35. flask.flash(firmName)
  36. flask.flash(jobTitle)
  37. flask.flash(jobCity)
  38. flask.flash(number)
  39. break
  40. else:
  41. n+=1
  42.  
  43. def getPhoneAlt(v):
  44. v=0
  45. while v<29:
  46. number = moreSoup.find_all('li')[v].text
  47. if re.match(regNum,number):
  48. flask.flash(number)
  49. break
  50. else:
  51. v+=1
  52.  
  53. def googShortUrl(url):
  54. post_url = 'https://www.googleapis.com/urlshortener/v1/'+url
  55. payload = {'longUrl': url}
  56. headers = {'content-type':'application/json'}
  57. r = requests.post(post_url, data=json.dumps(payload), headers=headers)
  58. text = r.content
  59. text = json.loads(text)
  60. return (text['id'])
  61.  
  62. def post(self):
  63. what = flask.request.form['what']
  64. where = flask.request.form['where']
  65. jobType = flask.request.form['jt']
  66. salary = flask.request.form['salary']
  67. fromage = flask.request.form['fromage']
  68. i=0
  69. while i<10:
  70. indeedSite = 'http://www.indeed.com/jobs?as_and='+what+'&as_phr=&as_any=&as_not=&as_ttl=&as_cmp=&jt='+jobType+'&st=&sr=directhire&salary='+salary+'&radius=25&l='+where+'&fromage='+fromage+'&limit=10&sort=&psf=advsrch'
  71. r = requests.get(indeedSite)
  72. soup = BeautifulSoup(r.content)
  73. g_data = soup.find_all('div', {'class': 'row'})
  74. for item in g_data:
  75. try:
  76. firmName = item.find_all('span',{'class':'company'})[0].text
  77. jobTitle = item.find_all('a',{'target':'_blank'})[0].text
  78. jobCity = item.find_all('span',{'class':'location'})[0].text
  79. jobCityPlus = re.sub(', ','+',jobCity)
  80. firmNamePlus = re.sub("\'",'',firmName)
  81. firmNamePlus = re.sub(' ','+',firmName)+'+'
  82. bingSearch = 'http://www.bing.com/search?q='+firmNamePlus+jobCityPlus
  83. info = requests.get(bingSearch)
  84. moreSoup = BeautifulSoup(info.content)
  85. contactData = moreSoup.find_all('div',{'class':"b_factrow"})
  86. number = contactData[0].text
  87. if getPhone(0) is not None:
  88. getPhone(0)
  89. else:
  90. getPhoneAlt(0)
  91. flask.flash(firmName)
  92. flask.flash(jobCity)
  93. flask.flash(jobTitle)
  94. flask.flash(number)
  95. for link in item('a',href=re.compile('^/rc/clk\?jk=|^.*clk\?|^.*\?r=1')):
  96. source = 'http://www.indeed.com'+link.get('href')
  97. googShortUrl(source)
  98. flask.flash(source)
  99. except:
  100. pass
  101. i+=10
  102. return self.get()
  103.  
  104. app.add_url_rule('/',
  105. view_func=View.as_view('main'),
  106. methods=['GET','POST'])
  107.  
  108. app.debug = True
  109. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement