-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
65 lines (29 loc) · 1.06 KB
/
main.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
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
import wikipedia
import requests
Builder.load_file('frontend.kv')
class FirstScreen(Screen):
def get_image_link(self):
## It gets user query from input
query = self.manager.current_screen.ids.user_query.text
##get wikipedia page and list of image urls
page = wikipedia.page(query)
image_link = page.images[0]
return image_link
def download_image(self):
req = requests.get(self.get_image_link())
imagepath = 'files/image2.jpg'
with open(imagepath, 'wb') as file:
file.write(req.content)
return imagepath
def set_image(self):
##Set the image in the image widget
self.manager.current_screen.ids.img.source = self.download_image()
class RootWidget(ScreenManager):
pass
class MainApp(App):
def build(self):
return RootWidget()
MainApp().run()