-
Notifications
You must be signed in to change notification settings - Fork 3
/
__init__.py
61 lines (51 loc) · 2.53 KB
/
__init__.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
import sys
import dbus
import requests
import random
import os
import time
from io import open as iopen
from traceback import print_exc
from os.path import dirname
from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill, intent_handler
from mycroft.util.log import getLogger
__author__ = 'aix'
LOGGER = getLogger(__name__)
class UnsplashPlasmaWallpaperSkill(MycroftSkill):
# The constructor of the skill, which calls MycroftSkill's constructor
def __init__(self):
super(UnsplashPlasmaWallpaperSkill, self).__init__(name="UnsplashPlasmaWallpaperSkill")
@intent_handler(IntentBuilder("UnsplashKeywordIntent").require("UnsplashPlasmaDesktopSkillKeyword").build())
def handle_unsplash_plasma_desktopskill_intent(self, message):
utterance = message.data.get('utterance').lower()
utterance = utterance.replace(
message.data.get('UnsplashPlasmaDesktopSkillKeyword'), '')
searchString = utterance
rawrinpt = str(searchString)
category = rawrinpt
size = '1920x1080'
file_url = 'https://source.unsplash.com/' + size + '/' + '?' + category
suffix_random = str(random.randint(1111,9999))
file_name = category + suffix_random
i = requests.get(file_url)
if i.status_code == requests.codes.ok:
ossep = os.path.sep
directory = os.path.realpath(os.getcwd() + ossep + "pictures" + ossep)
if not os.path.exists(directory):
time.sleep(1)
os.makedirs(directory)
with iopen(directory + ossep + file_name + '.jpg', 'wb') as file:
file.write(i.content)
file.close()
currdir = os.getcwd()
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.plasmashell","/PlasmaShell")
remote_object.evaluateScript('var allDesktops = desktops();print (allDesktops);for (i=0;i<allDesktops.length;i++) {d = allDesktops[i];d.wallpaperPlugin = "org.kde.image";d.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General");d.writeConfig("Image", "file://' + currdir + '/pictures/' + file_name + '.jpg' + '")}', dbus_interface = "org.kde.PlasmaShell")
#self.speak_dialog("krunner.search", data={'Query': searchString})
def stop(self):
pass
# The "create_skill()" method is used to create an instance of the skill.
# Note that it's outside the class itself.
def create_skill():
return UnsplashPlasmaWallpaperSkill()