Example #1
0
    def initialize(self):
        self.add_event('pixabay-skill.aiix.home',
                       self.handle_pixabay_homescreen)
        self.gui.register_handler("pixabay.show.image",
                                  self.handle_pixabay_show_image)
        self.gui.register_handler("pixabay.show.video",
                                  self.handle_pixabay_show_video)
        self.gui.register_handler("pixabay.gallery.next",
                                  self.handle_gallery_next_page)
        self.gui.register_handler("pixabay.gallery.previous",
                                  self.handle_gallery_previous_page)
        self.gui.register_handler("pixabay.idle.set_idle",
                                  self.handle_set_idlescreen_type)
        self.gui.register_handler("pixabay.idle.enableTime",
                                  self.handle_idle_enable_time)
        self.gui.register_handler("pixabay.idle.disableTime",
                                  self.handle_idle_disable_time)
        self.gui.register_handler("pixabay.idle.updateTime",
                                  self.handle_idle_update_time)
        self.gui.register_handler("pixabay.idle.removeConfigPage",
                                  self.handle_remove_configure_idle_screen)
        self.entKey = base64.b64decode(
            "MTcyMjI5NDctYTlmNTQxNmQ2ODhkNDVmNmJkZmY4ZWEzYQ==")
        self.video = Video(self.entKey)
        self.image = Image(self.entKey)
        self.shownPageNumber = None
        self.numberOfAvailablePages = None
        self.previousQuery = None
        self.currentType = None
        self.currentDir = dirname(dirname(abspath(__file__)))
        self.wantedDir = "pixabayData"
        self.dataPath = join(self.currentDir, self.wantedDir)
        self.videoPath = join(self.dataPath, "video.mp4")

        # Set All Paths
        try:
            os.mkdir(self.dataPath)
        except OSError as error:
            print("Directory Already Exist Skipping")
        self.storeDB = join(self.dataPath, 'pixabay-idle.db')
        self.idle_db = JsonStorage(self.storeDB)
        self.configDB = join(self.dataPath, 'pixabay-config.db')
        self.idle_config_db = JsonStorage(self.configDB)

        # Make Import For TimeData
        try:
            time_date_path = "/opt/mycroft/skills/mycroft-date-time.mycroftai/__init__.py"
            time_date_id = "datetimeskill"
            datetimeskill = load_skill_module(time_date_path, time_date_id)
            from datetimeskill import TimeSkill
            self.dt_skill = TimeSkill()
        except:
            print("Failed To Import DateTime Skill")
Example #2
0
# Assign your Api key to the environment variable "PIXABAY_API_KEY" and the working variable API_KEY
os.environ["PIXABAY_API_KEY"] = YOUR_API_KEY
API_KEY = YOUR_API_KEY

# Search for any image using the Image query
Image = Image(API_KEY)
newImage = Image.search(q='YOUR_SEARCH')

# Pretty print response to improve readability
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(newImage)

# Get the value for the preview URL
payload_one = newImage['hits'][15]['previewURL']
print("This is the preview URL {}".format(payload_one))

# Search for any video using the Video query
Video = Video(API_KEY)
newVideo = Video.search(q='YOUR_SEARCH')

# Pretty print response to improve readability
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(newVideo)

# Get the value for a particular video URL
payload_two = newVideo['hits'][0]['videos']['medium']['url']
print("This is the preview URL {}".format(payload_two))

# Download the particular video
urllib.request.urlretrieve(payload_two, 'FirstVid.mp4')
from unittest import TestCase
from pixabay import Image, Video
import os

api_key = os.getenv('PIXABAY_API_KEY')
image = Image(api_key)
video = Video(api_key)


class TestPythonPixabay(TestCase):
    def test_custom_image_search(self):
        self.assertIn(
            "hits",
            image.search(q="water",
                         page=1,
                         safesearch="true",
                         editors_choice="true"))
        self.assertEqual(
            image.search(q="apple", page=1)["hits"][0]["pageURL"],
            "https://pixabay.com/photos/apples-fruit-red-juicy-ripe-634572/")
        self.assertEqual(
            image.search(q="apple",
                         page=1,
                         safesearch="false",
                         editors_choice="true")["totalHits"], 155)

    def test_custom_video_search(self):
        self.assertEqual(
            video.search(q="apple",
                         page=1,
                         safesearch="false",
Example #4
0
# keywords test mode (by passing a sentence as arguments)
if len(sys.argv) > 1:
    # get text from system arguments
    sentence = " ".join(sys.argv[1:])
    keywords = get_keywords(sentence)
    keywords = [k[0] for k in Counter(keywords).most_common(5)] # keywords to search in order
    print("keywords", keywords)
    exit()
    
app = Flask(__name__)
PORT = int(os.environ.get("PORT", 3000))
PIXABAY_API_AUTH_KEY = os.environ.get(
    "PIXABAY_API_AUTH_KEY", config("PIXABAY_API_AUTH_KEY") or "Your API key from https://pixabay.com/api/docs/")

video = Video(PIXABAY_API_AUTH_KEY)
image = Image(PIXABAY_API_AUTH_KEY)

def get_updated_data(data):
    # avoid using repeated or cors blocked contents
    video_ids = set([15333, 6183])
    image_ids = set()
    for sentence in data["sentences"]:
        # per sentence
        min_duration = sentence["time"] / 1000
        max_duration = 60
        keywords = get_keywords(sentence["value"]) or [sentence["value"]]
        doc_keywords = nlp(" ".join(keywords)) # used for similarity
        keywords = [k[0] for k in Counter(keywords).most_common(5)] # keywords to search in order
        print("sentence:", sentence["value"], "\nkeywords", keywords)
        id_ = 0