Example #1
0
    def save_video(self, item: str, folder: str) -> bool:
        LOG.info(f"[Video] Trying to download {item.url} to {folder}")
        if not is_video(item):
            return False
        #

        return subprocess.call(['youtube-dl', item.url], cwd=folder) == 0
Example #2
0
 def _on_connect(self, client, userdata, flags, rc):
     if rc == 0:
         LOG.info("MQTT Client connected successfully to host {}".format(
             self.host))
         self.connected = True
     else:
         LOG.error("MQTT Client could not connect to host {}".format(
             self.host))
Example #3
0
 def __init__(self, mycroft, client_id: str, client_secret: str,
              user_agent: str):
     self.mycroft = mycroft
     self.reddit = praw.Reddit(client_id=client_id,
                               client_secret=client_secret,
                               user_agent=user_agent)
     self.limit = 1000
     LOG.info(f"{client_id}, {client_secret}, {user_agent}")
Example #4
0
 def render_image(self, image):
     self.publish("(oled:clear)")
     pixels = image_to_pixels(image)
     for pixel in pixels:
         x, y = pixel
         payload = f"(oled:pixel {x} {y})"
         LOG.info(payload)
         self.publish(payload)
Example #5
0
 def send_json(socket, data):
     # try:
     serialized = json.dumps(data.__dict__)
     LOG.info(serialized)
     # except (TypeError, ValueError) as e:
     #     raise Exception('You can only send JSON-serializable data')
     # send the length of the serialized data first
     socket.send('%d\n'.encode() % len(serialized))
     # send the serialized data
     socket.sendall(serialized.encode())
Example #6
0
 def get_reddit_replies(self, arg):
     result = []
     try:
         result = self.reddit.subreddit(arg).hot(limit=self.limit)
         LOG.info(f"Getting replies")
     except Exception as e:
         LOG.info(f"Got zero replies {e}")
         result = []
     finally:
         return result
Example #7
0
    def save_image(self, item: str, folder: str) -> bool:
        if not is_image(item):
            return False
        #

        filename = self.get_file_name(item)
        full_file_path = os.path.join(folder, filename)
        if os.path.exists(full_file_path):
            LOG.info(f"[File Exists] {filename}")
            return False
        #

        try:
            response = requests.get(item.url)
            if not response.ok:
                LOG.info("Error downloading file.")
                return False
        except Exception as e:
            LOG.info(f"Error downloading path {e}")
            return False
        #

        LOG.info(f"[File Saved] {filename}")
        pathlib.Path(full_file_path).write_bytes(response.content)

        return True
Example #8
0
    def download_photos_and_videos(self, data_type, community: str,
                                   video_folder: str, photos_folder: str,
                                   max_images: int, max_videos: int) -> None:

        current_images = 0
        current_videos = 0

        try:
            community_posts = self.get_reddit_replies(community)
        except Exception as e:
            self.mycroft.speak(
                f"Unable to reach reddit, verify the reddit skill configuration"
            )
            return
        #

        for item in community_posts:
            try:
                if (data_type
                        in [Reddit.DataTypes.ALL, Reddit.DataTypes.VIDEO]
                        and current_videos < max_videos
                        and self.save_video(item=item, folder=video_folder)):
                    current_videos += 1
                #

                if (data_type
                        in [Reddit.DataTypes.ALL, Reddit.DataTypes.IMAGES]
                        and current_images < max_images
                        and self.save_image(item=item, folder=photos_folder)):
                    current_images += 1
                #
            except Exception as e:
                LOG.info(f"Error trying to get {community}:")
                LOG.info(f"{e}")
            #

            # Break early from the loop if we finished downloading things
            if data_type == Reddit.DataTypes.IMAGES and current_images >= max_images:
                return
            #

            if data_type == Reddit.DataTypes.VIDEO and current_videos >= max_videos:
                return
            #

            if (data_type == Reddit.DataTypes.ALL
                    and current_videos >= max_videos
                    and current_images >= max_images):
                return
Example #9
0
def reverse():
    sleep(.5) # TODO: needs to be removed
    GPIO.output(DIR, GPIO.HIGH)
    LOG.info("DIR set to HIGH")

    LOG.info("Rotating CCW")
    GPIO.output(LED, GPIO.HIGH)
    for y in range(durationBwd):
        GPIO.output(PUL, GPIO.HIGH)
        sleep(delay)
        GPIO.output(PUL, GPIO.LOW)
        sleep(delay)
    GPIO.output(LED, GPIO.LOW)
    sleep(.5) # TODO: needs to be removed
    return
Example #10
0
def forward():
    sleep(.5) # TODO: needs to be removed
    GPIO.output(DIR, GPIO.LOW)
    LOG.info("DIR set to LOW")

    LOG.info("Rotating CW")
    GPIO.output(LED, GPIO.HIGH)
    for x in range(durationFwd): 
        GPIO.output(PUL, GPIO.HIGH)
        sleep(delay)
        GPIO.output(PUL, GPIO.LOW)
        sleep(delay)
    GPIO.output(LED, GPIO.LOW)
    sleep(.5) # TODO: needs to be removed
    return
Example #11
0
    def get_video_url(self, reddit_url: str) -> str:
        try:
            if ("gfycat" in reddit_url):
                extra_params = []
            elif ("youtube" in reddit_url):
                extra_params = ["--format", "best[height<=480]"]

            youtube_dl_params = ["youtube-dl", "--get-url"]
            for param in extra_params:
                youtube_dl_params.append(param)

            youtube_dl_params.append(reddit_url)

            video_url = subprocess.check_output(youtube_dl_params).decode(
                "utf-8")

            LOG.info(f"Getting Video URL Video Url: {video_url}")
            return video_url
        except Exception as e:
            LOG.info(f"{e}")
            return ""
Example #12
0
    def download(self, data_type, communities: List[str], download_folder: str,
                 max_images: int, max_videos: int) -> None:

        LOG.info(f"Inside of the reddit library {data_type}")
        total = len(communities)
        for community in communities:
            idx = communities.index(community)
            LOG.info(f"Trying to get {community}")

            video_folder = folder(download_folder=download_folder,
                                  subfolder="video",
                                  community=community)

            photos_folder = folder(download_folder=download_folder,
                                   subfolder="images",
                                   community=community)

            self.download_photos_and_videos(data_type=data_type,
                                            community=community,
                                            video_folder=video_folder,
                                            photos_folder=photos_folder,
                                            max_images=max_images,
                                            max_videos=max_videos)
Example #13
0
def stop():
    GPIO.output(ENA, GPIO.LOW)
    LOG.info("Stopping stepper...")
Example #14
0
def start():
    GPIO.output(ENA, GPIO.HIGH)
    LOG.info("Starting stepper...")
    run()
Example #15
0
def cleanup():
    GPIO.cleanup()
    LOG.info("Cleanup for stepper...")
Example #16
0
except:
    is_imported = False
    pass


PUL = 17  # Driver pulse
DIR = 27  # Driver direction
ENA = 22  # Driver enable
LED = 18  # Indicator


if is_imported:
    GPIO.setmode(GPIO.BCM)

    GPIO.setup(PUL, GPIO.OUT)
    LOG.info("PUL = GPIO 17")
    GPIO.setup(DIR, GPIO.OUT)
    LOG.info("PUL = GPIO 27")
    GPIO.setup(ENA, GPIO.OUT)
    LOG.info("PUL = GPIO 22")
    GPIO.setup(LED, GPIO.OUT)
    LOG.info("PUL = GPIO 18")


    LOG.info("GPIO Setup Complete.")


durationFwd = 200 # Forward spin duration (full rotation 1600)
durationBwd = 200 # Reverse spin duration
delay = 0.0000002 # Delay between PUL.
Example #17
0
# How to create a sky remote:
#from sky_remote import SkyRemote
#remoteControl = sky_remote.SkyRemote('192.168.0.40')
## Just send a command
#remoteControl.press('power')
## Now send sequences of commands
#remoteControl.press(['channelup', 'record', 'select'])

#Sky Q (if firmware < 060):
#remoteControl = SkyRemote('192.168.0.40', SkyRemote.SKY_Q_LEGACY)

# All the buttons that can be pressed:
# sky power
# tvguide or home boxoffice services or search interactive or sidebar
# up down left right select
# channelup channeldown i
# backup or dismiss text help
# play pause rewind fastforward stop record
# red green yellow blue
# 0 1 2 3 4 5 6 7 8 9

if __name__ == '__main__':
    # If there aren't any skyqs listed in the file, then we start the discover process
    skyq_list = read_discovered()
    if skyq_list is None or not skyq_list:
        write_discovered()
        skyq_list = read_discovered()

    # Print out the list
    LOG.info(skyq_list)
Example #18
0
def _get(url):
    LOG.info(url)
    return requests.get(url)
Example #19
0
def set_volume(speaker, wanted_volume):
    if wanted_volume > MAX_VOLUME:
        LOG.info('Max volume exceeded. Wanted {}, max volume is {}')
        wanted_volume = MAX_VOLUME
    return get(API_URL + speaker + '/' + 'volume/' + str(wanted_volume))