Created
May 5, 2023 16:10
-
-
Save htlin222/cb0dbc7195a8bf12d5855b22b6e5d73b to your computer and use it in GitHub Desktop.
Raycast Command, save clipboard content to the simplenote, generate title by ChatGPT api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# title: clip_to_simplenote | |
# date: "2023-03-11" | |
# @raycast.title Clipboard to Simplenote with Anki tag | |
# @raycast.author HTLin the π¦ | |
# @raycast.authorURL https://github.com/htlin222 | |
# @raycast.description Take the clipboard to simplenote | |
# @raycast.icon π | |
# @raycast.mode silent | |
# @raycast.packageName System | |
# @raycast.schemaVersion 1 | |
import simplenote | |
import pyperclip | |
import openai | |
import re | |
openai.api_key = 'YOUR_API_KEY' | |
# Authenticate Simplenote using your email and password | |
email = "YOUR_EMALI" | |
password = "YOUR_PASSWORD" | |
note_store = simplenote.Simplenote(email, password) | |
# Get the current clipboard content using Pyperclip | |
note_body = pyperclip.paste() | |
def generate_titles(note_body): | |
prompt = 'give a title (less than 10 words) for <text>, do not add quote to title:\n' | |
full_prompt = prompt + note_body | |
response = openai.Completion.create( | |
model="text-davinci-003", | |
prompt=full_prompt, | |
max_tokens=2000, | |
temperature=0.5, | |
) | |
title = response["choices"][0]["text"] | |
title = re.sub(r'^[\W\s]+', '', title) | |
return title | |
# uncomment the following lines if you want to generate title by ChatGPT | |
# title = generate_titles(note_body) | |
# note_body = title + "\n" + note_body | |
# note_body = note_body.lstrip('\n') | |
# Save the note to Simplenote with the tag "anki" | |
note_store.add_note({'content': note_body, 'tags': ['anki']}) | |
print("Done π ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment