diff --git a/cohost/models/project.py b/cohost/models/project.py index 44bdfb8..cfe3962 100644 --- a/cohost/models/project.py +++ b/cohost/models/project.py @@ -105,6 +105,16 @@ def getPosts(self, page=0) -> list: posts.append(Post(post, self)) return posts + def ask(self, content, sourceProject, anon=False): + from cohost.models.project import EditableProject + if type(sourceProject) != EditableProject: + raise TypeError("sourceProject must be an editable project") + sourceProject = sourceProject # EditableProject + fetchTrpc('asks.send', sourceProject.user.cookie, { + "toProjectHandle": self.handle, + "content": content, + "anon": anon}, methodType='postjson') + class EditableProject(Project): def __init__(self, user, projectId): diff --git a/cohost/network.py b/cohost/network.py index f425458..a0d9cf6 100644 --- a/cohost/network.py +++ b/cohost/network.py @@ -80,13 +80,15 @@ def fetchTrpc(methods: list, cookie: str, m = methods else: m = ','.join(methods) - cacheData = get_cache_data(cookie, m) - if cacheData is not None: - logger.debug('Cache hit!') - return cacheData + if methodType == "get": + cacheData = get_cache_data(cookie, m) + if cacheData is not None: + logger.debug('Cache hit!') + return cacheData data = fetch(methodType, "/trpc/{}".format(m), data=data, cookies=generate_login_cookies(cookie)) - set_cache_data(cookie, m, data) + if methodType == "get": + set_cache_data(cookie, m, data) return data diff --git a/demos/releaseNotes/0.3.png b/demos/releaseNotes/0.3.png new file mode 100644 index 0000000..b374b12 Binary files /dev/null and b/demos/releaseNotes/0.3.png differ diff --git a/demos/releaseNotes/0.3.py b/demos/releaseNotes/0.3.py new file mode 100644 index 0000000..dbe4473 --- /dev/null +++ b/demos/releaseNotes/0.3.py @@ -0,0 +1,61 @@ +import os +from cohost.models.user import User +from cohost.models.block import AttachmentBlock, MarkdownBlock + +def generateWarningNote(message: str, title = "Heads up! :eggbug-pleading:"): + # stolen from https://cohost.org/aristurtle/post/176671-admonitions-on-cohos + return """
+

+ ⚠️ {} +

+

+ {} +

+
""".format(title, message) + +def generateDangerNote(message: str, title = "Danger! :eggbug-shocked:"): + # stolen from https://cohost.org/aristurtle/post/176671-admonitions-on-cohos + return """
+

+ 🔺 {} +

+

+ {} +

+
""".format(title, message) + +def main(): + username = os.environ.get('cohostUser') + password = os.environ.get('cohostPass') + handle = os.environ.get('cohostHandle') + if username is None: + username = input('username: ') + if password is None: + password = input('password: ') + if handle is None: + handle = input('handle: ') + + blocks = [ + AttachmentBlock("0.3.png", alt_text="Two python-eggbugs photoshopped ontop of the two sickos from the sickos meme.\ + Labels say \"Sicko to sicko communication\" and \"Sicko to sicko conversation\""), + MarkdownBlock('
cohost.py 0.3 is out!!
'), + MarkdownBlock('this update contains the ability to send other pages asks via the API. reading your asks is not yet supported, but, is coming soon(TM)'), + MarkdownBlock('as always you can install cohost.py with `pip install cohost` - enjoy chosting!'), + MarkdownBlock(generateWarningNote("Cohost.py is still experimental, etc etc etc... you get the picture. Please submit bugs, feature requests and PRs to the GitHub repo!")), + MarkdownBlock(generateDangerNote('If you\'re making a bot, please honor @jkap\'s little notes on bots! And, as always, don\'t make this site awful :)')), + MarkdownBlock('
'), + MarkdownBlock('check out the source for this post'), + MarkdownBlock("
"), + MarkdownBlock('ps: feature requests, bug reports and PRs? super welcome. check out our github. pybug is waiting.') + + ] + # woah !!! logging in !!! that's so cool !!! + user = User.login(username, password) + project = user.getProject(handle) + otherProject = user.getProject("vallerie") + otherProject.ask("woah hello from cohost.py", project, True) + newPost = project.post('cohost.py 0.3 - the ask-y update', blocks, tags=['cohost.py', 'python', 'development', 'cohost api'], draft=False) + print('Check out your post at {}'.format(newPost.url)) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index dafb1e3..1c98497 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "cohost" -version = "0.2.6" +version = "0.3.0" description = "Unofficial Python API wrapper for Cohost.org - the fourth website!" readme = "README.md" requires-python = ">=3.9"