def jobs(request): # variables declared with HTTP GET, otherwise defaults provided job = request.GET.get('job', 'java') location = request.GET.get('location', 'california') # TODO - These should be found in the HTTP request headers user_ip = request.GET.get('user_ip', '11.22.33.44') url = request.GET.get('url', 'http://www.example.com/jobsearch?q=python&l=london') user_agent = request.GET.get('user_agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0') # Look for keywords in database results = SearchResult.objects.filter(job=job, location=location) # If length of results is 0 if len(results) == 0: all_jobs = indeed_query(job, location, user_ip, user_agent) new_result = SearchResult(job=job, location=location, result=json.dumps(all_jobs, sort_keys=True, indent=0, separators=(',', ': '))) new_result.save() results = [new_result] return JsonResponse({ 'jobs': json.loads(results[0].result) })
def search_google(request): if(request.method==GET): keywords = request.GET["keywords"] response = gcs.search(q=keywords) SearchString.objects.filter(words=keywords).delete() searchstring = SearchString(words=keywords) searchstring.save() for item in response['items']: searchresult = SearchResult(searchstring=searchstring, result_title=item['htmlTitle'], result_url=item['link']) searchresult.save() return JsonResponse({'search_id': searchstring.id , 'data':response})
def saveResult(self, tweet, query): try: sr = SearchResult() sr.screenName = tweet.user.screen_name sr.userId = tweet.user.id sr.tweetId = tweet.id #sr.text = tweet.text sr.query = query #sr.tweetedTime = tweet.created_at sr.lang = tweet.lang sr.save() except Exception as e: if e[0] == 1366: log.info("Error no 1366, removing text") sr.text = None sr.save() else: raise e
def saveResult(self, tweet, query): try: sr = SearchResult() sr.screenName = tweet.user.screen_name sr.userId = tweet.user.id sr.tweetId = tweet.id #sr.text = tweet.text sr.query=query #sr.tweetedTime = tweet.created_at sr.lang = tweet.lang sr.save() except Exception as e: if e[0] == 1366: log.info("Error no 1366, removing text") sr.text=None sr.save() else: raise e