Skip to content

Commit

Permalink
version 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannicoppola committed Feb 28, 2023
1 parent 2ac4129 commit 1ce9945
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 3,604 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ src="https://img.shields.io/github/downloads/giovannicoppola/alfred-kindle/total
## Default settings
- In Alfred, open the 'Configure Workflow' menu in `alfred-kindle` preferences
- set the keyword for the workflow (default: `!k`)
- set the book content icon, i.e. if a book has been downloaded locally. (default: 📘)
- show 'ghost' books (i.e. books not downloaded, or previously loaned)? (default: yes)
- set the book content icon, i.e. if a book has been downloaded locally (default: 📘)
- show 'ghost' books (i.e. books not downloaded, or previously loaned)? (default: yes)
- set search scope (default: 'Title')
- `Title`: search titles only
- `Author`: search authors only
Expand Down
Binary file added images/kindle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added releases/alfred-kindle_0.1.alfredworkflow
Binary file not shown.
65 changes: 60 additions & 5 deletions source/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<key>createdby</key>
<string>giovanni</string>
<key>description</key>
<string></string>
<string>Browse and open your Kindle books</string>
<key>disabled</key>
<false/>
<key>name</key>
Expand Down Expand Up @@ -109,7 +109,60 @@ python3 kindle-query.py "$1"
</dict>
</array>
<key>readme</key>
<string></string>
<string># alfred-kindle 📚
List and open your Kindle books with Alfred
## Motivation ✅
- Quickly list, search, and open your Kindle books
## Setting up ⚙️
- Alfred 5 with Powerpack license
- Python3
- Kindle app installed
### Default settings
- In Alfred, open the 'Configure Workflow' menu in `alfred-kindle` preferences
- set the keyword for the workflow (default: `!k`)
- set the book content icon, i.e. if a book has been downloaded locally (default: 📘)
- show 'ghost' books (i.e. books not downloaded, or previously loaned)? (default: yes)
- set search scope (default: 'Title')
- `Title`: search titles only
- `Author`: search authors only
- `Both`: search across titles and authors
## Basic Usage 📖
- launch with keyword (default: `!k`), or custom hotkey
- `enter` ↩️ will open the book in Kindle (if downloaded) or the corresponding webpage on Amazon (if not downloaded)
## Limitations &amp; known issues ⚠️
- None for now, but I have not done extensive testing, let me know if you see anything!
- tested with ~100 books. The book list is currently created on the fly, and book covers are downloaded if missing. Might be slower if your library has thousands of books, in which case a sqlite database it might be more efficient. Let me know if that is the case!
- tested with Python 3.9.13
## Acknowledgments 😀
- Thanks to the [Alfred forum](https://www.alfredforum.com) community!
- Icon from [SF symbols](https://developer.apple.com/sf-symbols/)
## Changelog 🧰
- 02-28-2023: version 0.1
## Feedback 🧐
Feedback welcome! If you notice a bug, or have ideas for new features, please feel free to get in touch either on [Github](https://github.com/giovannicoppola/alfred-kindle), or on the [Alfred](https://www.alfredforum.com) forum.</string>
<key>uidata</key>
<dict>
<key>C201E860-5900-49B2-8980-4B8E5DA0A4C8</key>
Expand Down Expand Up @@ -182,7 +235,7 @@ python3 kindle-query.py "$1"
<string>Check to show 'ghost' books</string>
</dict>
<key>description</key>
<string>Books not downloaded, or previously loaned</string>
<string>Show books not downloaded locally, or previously loaned</string>
<key>label</key>
<string>Show 'ghost' books</string>
<key>type</key>
Expand Down Expand Up @@ -221,9 +274,11 @@ python3 kindle-query.py "$1"
<string>SEARCH_SCOPE</string>
</dict>
</array>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string></string>
<string>0.1</string>
<key>webaddress</key>
<string></string>
<string>https://github.com/giovannicoppola/alfred-kindle</string>
</dict>
</plist>
58 changes: 39 additions & 19 deletions source/kindle-query.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ def getKindleDB():
resultList.append(','.join(str(x) for x in result[i:i+10]))

return resultList
#print(resultList)



def GetKindleData(myList):
"""
A function to get kindle information using a third party API.
Currently not used in this workflow
"""
url = "https://amazon-product-price-data.p.rapidapi.com/product"

myResults = []
Expand All @@ -67,7 +73,7 @@ def GetKindleData(myList):
querystring = {"asins":myBatch,"locale":"US"}

headers = {
"X-RapidAPI-Key": "060192ca34msh77aa6624f8e5d93p186236jsn93b44b5109c8",
"X-RapidAPI-Key": "INSERT API KEY HERE",
"X-RapidAPI-Host": "amazon-product-price-data.p.rapidapi.com"
}

Expand All @@ -82,12 +88,25 @@ def GetKindleData(myList):
def getDownloadedBooks(basepath):
import os
myContentBooks = []

# List all subdirectories using scandir()
with os.scandir(basepath) as entries:
for entry in entries:
if entry.is_dir():
myContentBooks.append(entry.name.split("_")[0])
return myContentBooks
try:
with os.scandir(basepath) as entries:
for entry in entries:
if entry.is_dir():
myContentBooks.append(entry.name.split("_")[0])
return myContentBooks
except:
result= {"items": [{
"title": "Error: Cannot find Kindle directory",
"subtitle": basepath,
"arg": "",
"icon": {

"path": "icons/Warning.png"
}
}]}
print (json.dumps(result))

def getXML(myFile, downloaded):
## Importing the XML table
Expand All @@ -96,10 +115,7 @@ def getXML(myFile, downloaded):
data_dict = xmltodict.parse(xml_file.read())
xml_file.close()

#print (data_dict)

# with open('xml.json', 'w') as f:
# json.dump(data_dict, f,indent=4)
result = {"items": []}
myBooks = data_dict['response']['add_update_list']['meta_data']

Expand All @@ -118,7 +134,10 @@ def getXML(myFile, downloaded):
myFilteredBooks = [i for i in myBooks if (MYINPUT in i['authorString'].casefold())]
elif SEARCH_SCOPE == "Both":
myFilteredBooks = [i for i in myBooks if (MYINPUT in i['authorString'].casefold()) or (MYINPUT in i['title']['#text'].casefold())]



if GHOST_RESULTS == '0':
myFilteredBooks = [i for i in myFilteredBooks if (i['ASIN'] in downloaded)]

if MYINPUT and not myFilteredBooks:
result["items"].append({
Expand All @@ -130,14 +149,15 @@ def getXML(myFile, downloaded):
}

})
#print (json.dumps(result))






totalLibrary = (len(myFilteredBooks))
myCounter = 0

for book in myFilteredBooks:
#print (book['title']['#text'])


if book['ASIN'] in downloaded:
BookSymbol = BOOK_CONTENT_SYMBOL
Expand All @@ -160,19 +180,19 @@ def getXML(myFile, downloaded):
continue



myCounter += 1
result["items"].append({
"title": book['title']['#text']+BookSymbol,
'subtitle': book['authorString'],
'subtitle': f"{myCounter}/{totalLibrary} {book['authorString']}",
'valid': True,

"icon": {
"path": ICON_PATH
},
'arg': bookURL
})
log (len(data_dict['response']['add_update_list']['meta_data']))
log (len(myFilteredBooks))



print (json.dumps(result))

Expand Down
Loading

0 comments on commit 1ce9945

Please sign in to comment.