예제 #1
0
def handleQuery(query) -> object:
    if not query.isTriggered:
        return

    results = []

    for stickerDir in os.listdir(stickersDir):
        albert.info(os.path.join(stickersDir, stickerDir))
        if not os.path.isdir(os.path.join(stickersDir, stickerDir)):
            continue

        for img in os.listdir(os.path.join(stickersDir, stickerDir)):
            def fn():
                icon=os.path.join(stickersDir, stickerDir, img)
                albert.info(icon)
                item = albert.Item(
                    id=__title__,
                    text=stickerDir + ': ' + img,
                    subtext=stickerDir,
                    icon=icon,
                    actions=[
                        albert.FuncAction(text="Copy Image", callable=lambda: doCopy(icon))
                    ]
                )

                results.append(item)
            fn()

    return results
예제 #2
0
def handleList(query):
    if len(config.sections()) == 0:
        # Try to reload the config.
        config.read(calendar_configuration_file)
        if len(config.sections()) == 0:
            info("No sections defined in config.")
            return Item(id="config",
                        icon=unresolved_todo,
                        text="Configuration not complete",
                        subtext="No sections in the Configuration file",
                        actions=[
                            ProcAction(
                                text="Edit configuration in default editor",
                                commandline=['xdg-open',
                                             calendar_configuration_file],
                                cwd="~"),
                            ClipAction(
                                text="Copy the path of the configuration file",
                                clipboardText=calendar_configuration_file)
                        ])
        else:
            connections.set_connections(config)
            connections.load_todos()
    items = []
    connections.refresh()
    for todo in connections.query(query.string):
        items.append(buildItem(todo))

    return items
def flush_history():
    v0.info(f"Flushing google_translate history -> {history_path}...")
    # TODO this kind of usage is theoretically unsafe, but most likely wont affect. The timer
    # fires every ~1hr and traversing the deque takes so little time.
    with open(history_path, "w") as f:
        for di in history_deque:
            f.write(f"{di}\n")
예제 #4
0
 def set_connections(self, conf: configparser.ConfigParser):
     self.config = conf
     self.Connections = {}
     for section in conf.sections():
         info(f"loading {section}")
         self.Connections[section] = caldav.DAVClient(
             url=conf[section]['url'],
             username=conf[section]['username'],
             password=conf[section]['password']).principal()
def launch_vlc():
    if vlc_socket.exists():
        if not vlc_socket.is_socket():
            raise RuntimeError(
                f'Exected socket file "{vlc_socket}" is not a socket')
        else:
            v0.info("VLC RC Interface is already up.")
    else:
        # communicate over UNIX socket with vlc
        subprocess.Popen(["vlc", "-I", "oldrc", "--rc-unix", vlc_socket])
예제 #6
0
 def createTodo(self, name, summary, due=None):
     todo = vobject.iCalendar()
     todo.add('vtodo')
     todo.vtodo.add('summary').value = summary
     if due:
         todo.vtodo.add('due').value = due
     for cal in self.Connections[name].calendars():
         if cal.canonical_url == self.config[name]["url"]:
             cal.add_todo(todo.serialize())
             info("added todo")
             self.todos.append(todo)
예제 #7
0
 def sortByDue(todo):
     obj = todo["todo"]
     if "due" in obj.vtodo.contents.keys():
         dueDate: datetime = obj.vtodo.due.valueRepr()
         if not isinstance(dueDate, datetime.datetime):
             dueDate = datetime.datetime.combine(
                 dueDate, datetime.datetime.min.time())
         if dueDate.tzinfo is None:
             dueDate = dueDate.astimezone()
     else:
         dueDate = None
     info(dueDate)
     return dueDate
예제 #8
0
            def fn():
                icon=os.path.join(stickersDir, stickerDir, img)
                albert.info(icon)
                item = albert.Item(
                    id=__title__,
                    text=stickerDir + ': ' + img,
                    subtext=stickerDir,
                    icon=icon,
                    actions=[
                        albert.FuncAction(text="Copy Image", callable=lambda: doCopy(icon))
                    ]
                )

                results.append(item)
예제 #9
0
 def postpone(self, name, uid, due):
     todo = self.findTodo(name, uid)
     if todo:
         info(todo.vobject_instance.vtodo.summary.valueRepr())
         info(todo.vobject_instance.vtodo.uid.valueRepr())
         info(todo.vobject_instance.vtodo.contents.keys())
         if "due" in todo.vobject_instance.vtodo.contents.keys():
             todo.vobject_instance.vtodo.due.value = due
         else:
             todo.vobject_instance.vtodo.add('due').value = due
         todo.save()
         self.load_todos()
예제 #10
0
def buildItem(todo):
    obj = todo["todo"]
    uid = obj.vtodo.uid.valueRepr()
    text = "{}: {}".format(todo["source"][0], obj.vtodo.summary.valueRepr())
    iconPath = unresolved_todo
    subtext = "no due date"
    urgency = ItemBase.Urgency.Alert
    onehour = datetime.datetime.now() + datetime.timedelta(hours=1)

    tonight = datetime.datetime.now()
    tonight = tonight.replace(hour=16, minute=0, second=0)

    tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
    tomorrow.replace(hour=9, minute=0, second=0)  # always 9 AM

    nextweek = datetime.datetime.now() + datetime.timedelta(days=7)
    nextweek.replace(hour=9, minute=0, second=0)  # always 9 AM

    if "due" in obj.vtodo.contents.keys():
        dueDate: datetime = obj.vtodo.due.valueRepr()
        if not isinstance(dueDate, datetime.datetime):
            dueDate = datetime.datetime.combine(
                dueDate, datetime.datetime.min.time())
            # dueDate = dueDate.replace(
            #     hour=9, minute=0, second=0)  # always 9 am
        if dueDate.tzinfo is None:
            dueDate = dueDate.astimezone()
        info(dueDate)
        now = datetime.datetime.now().astimezone()
        info(now)
        if dueDate < now:
            subtext = "� due: {:%Y-%m-%d %H:%M}".format(dueDate)
            urgency = ItemBase.Urgency.Normal
        elif (dueDate - now) < datetime.timedelta(hours=12):
            subtext = "⚠� due: {:%Y-%m-%d %H:%M}".format(dueDate)
            urgency = ItemBase.Urgency.Notification
        else:
            subtext = "🕑 due: {:%Y-%m-%d %H:%M}".format(dueDate)
    else:
        dueDate = datetime.datetime.now()

    return Item(
        id=f'{dueDate.timestamp()}',
        text=text,
        subtext=subtext,
        icon=iconPath,
        completion=f't {obj.vtodo.summary.valueRepr()}',
        urgency=urgency,
        actions=[FuncAction(text="Mark done",
                            callable=lambda: connections.markDone(
                                todo["source"][0], uid)),

                 FuncAction(text="Postpone for one hour",
                            callable=lambda: connections.postpone(
                                todo["source"][0], uid, onehour)),

                 FuncAction(text="Postpone ' till 4 P.M.'",
                            callable=lambda: connections.postpone(
                                todo["source"][0], uid, tonight)),

                 FuncAction(text="Postpone 'till tomorrow",
                            callable=lambda: connections.postpone(
                                todo["source"][0], uid, tomorrow)),
                 FuncAction(text="Postpone 'till next week",
                            callable=lambda: connections.postpone(
                                todo["source"][0], uid, nextweek)),
                 FuncAction(text="Reload todo's",
                            callable=lambda: connections.load_todos()),
                 ]
    )
예제 #11
0
 def do_reload():
     v0.info("TaskWarrior: Updating list of tasks...")
     tw_side.reload_items = True
     tw_side.get_all_items(include_completed=False)
예제 #12
0
def handleQuery(query):
    if query.isTriggered and query.string.strip():

        # avoid rate limiting
        time.sleep(0.2)
        if not query.isValid:
            return

        info("Searching YouTube for '{}'".format(query.string))
        req = Request(headers=HEADERS,
                      url='https://www.youtube.com/results?{}'.format(
                          urlencode({'search_query': query.string.strip()})))

        with urlopen(req) as response:
            responseBytes = response.read()
            match = re.search(DATA_REGEX, responseBytes.decode())
            if match is None:
                critical(
                    "Failed to receive expected data from YouTube. This likely means API changes, but could just be a failed request."
                )
                logHtml(responseBytes)
                return

            results = json.loads(match.group(3))
            results = results['contents']['twoColumnSearchResultsRenderer'][
                'primaryContents']['sectionListRenderer']['contents'][0][
                    'itemSectionRenderer']['contents']
            items = []
            for result in results:
                for type, data in result.items():
                    try:
                        if type == 'videoRenderer':
                            subtext = ['Video']
                            action = 'Watch on Youtube'
                            link = 'watch?v={}'.format(data['videoId'])

                            if 'lengthText' in data:
                                subtext.append(textFrom(data['lengthText']))
                            if 'shortViewCountText' in data:
                                subtext.append(
                                    textFrom(data['shortViewCountText']))
                            if 'publishedTimeText' in data:
                                subtext.append(
                                    textFrom(data['publishedTimeText']))

                        elif type == 'channelRenderer':
                            subtext = ['Channel']
                            action = 'Show on Youtube'
                            link = 'channel/{}'.format(data['channelId'])

                            if 'videoCountText' in data:
                                subtext.append(textFrom(
                                    data['videoCountText']))
                            if 'subscriberCountText' in data:
                                subtext.append(
                                    textFrom(data['subscriberCountText']))
                        else:
                            continue
                    except Exception as e:
                        critical(e)
                        critical(json.dumps(result, indent=4))

                    item = Item(
                        id=__title__,
                        icon=data['thumbnail']['thumbnails'][0]['url'].split(
                            '?', 1)[0]
                        if data['thumbnail']['thumbnails'] else __icon__,
                        text=textFrom(data['title']),
                        subtext=' | '.join(subtext),
                        actions=[
                            UrlAction(action,
                                      'https://www.youtube.com/' + link)
                        ])
                    items.append(item)
            return items