-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchGuide.py
43 lines (34 loc) · 1.43 KB
/
searchGuide.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
import requests
import time
import json
import os
from re import search
import configparser
config = configparser.ConfigParser()
config.read('config.ini')
KEY = config['guides']['KEY']
SITE_ID = config['guides']['SITE_ID']
URL = 'https://lgapi-au.libapps.com/1.1/guides?site_id='+SITE_ID+'&key='+KEY+'&sort_by=relevance&expand=pages&status=1'
data = ''
def checkGuide(keyword):
global URL, data
results_index = []
resultsData = ''
keywords = keyword.split(',')
for i in range(0,len(keywords)):
keywords[i] = keywords[i].lower()
data = requests.get(URL,timeout=60)
jsonData = data.content.decode("utf-8")
data = json.loads(jsonData)
for count in range (0, int(len(data))):
name = data[count]["name"].lower()
description = data[count]["description"].lower()
for keyword in keywords:
if (search(keyword, description) or search(keyword, description)):
results_index.append(count)
if resultsData == '':
resultsData = str('{"name":"%s","urllink":"%s","datepublished":"%s"}' % (data[count]["name"], data[count]["url"],data[count]["published"]))
else:
resultsData = resultsData + str(',{"name":"%s","urllink":"%s","datepublished":"%s"}' % (data[count]["name"],data[count]["url"],data[count]["published"]))
resultsData = '['+ resultsData +']'
return resultsData