forked from chitranshu651/Linus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.py
65 lines (61 loc) · 2.52 KB
/
search.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
import json
from urllib.parse import quote
from urllib.request import urlopen
import xml.etree.ElementTree as ET
import firefox
def wolfram(parameter):
from credentials import app_id
url = "http://api.wolframalpha.com/v2/query?input="+parameter['query'].replace(" ","+").replace("#","+")+"&appid="+app_id
xml_data = urlopen(url).read()
root = ET.fromstring(xml_data)
title = parameter['query']
order = []
Image = []
URI = []
Text = []
print('url: ' + url)
print("----"*10)
for pod in root.findall('pod'):
print('-------------------------------------------\n\n')
print(str(pod.attrib).split("'")[3])
Text.append({"data": str(pod.attrib).split("'")[3]})
order.append(3)
for img in pod.iter('img'):
print(str(img.attrib).split("'")[3])
Image.append({"src": str(img.attrib).split("'")[3],"placeHolder":'#'})
order.append(1)
Text.append({"data":"Powered by the Wolfram Language"})
order.append(3)
file = open('/home/iosdev747/Desktop/Linus/Linus/output.txt', 'w')
data = {}
data['title'] = title.replace('+', ' ')
data['order'] = order
data['Image'] = Image
data['URI'] = URI
data['Text'] = Text
data['command'] = ""
json_data = json.dumps(data)
file.write(json_data)
exit(0)
def google(parameter):
parameter['search-string'] = parameter['search-string'].replace("#"," ")
if parameter['search-engine'] == 'Google':
parameter['url'] = 'https://google.com/search?q=' + quote(parameter['search-string'])
elif parameter['search-engine'] == 'Wikipedia':
parameter['url'] = 'https://en.wikipedia.org/wiki/' + quote(parameter['search-string'])
elif parameter['search-engine'] == 'Amazon':
parameter['url'] = 'https://www.amazon.in/s/?field-keywords=' + quote(parameter['search-string'])
elif parameter['search-engine'] == 'DuckDuckGo':
parameter['url'] = 'https://duckduckgo.com/?q=' + quote(parameter['search-string'])
elif parameter['search-engine'] == 'Bing':
parameter['url'] = 'https://bing.com/search?q=' + quote(parameter['search-string'])
elif parameter['search-engine'] == 'Stackoverflow':
parameter['url'] = 'https://stackoverflow.com/search?q=' + quote(parameter['search-string'])
else:
parameter['url'] = 'wolfram'
parameter['query'] = parameter['search-string']
print(parameter['url'])
if not parameter['url'] == 'wolfram':
firefox.open_url(parameter)
else:
wolfram(parameter)