{"id":23423769,"url":"https://github.com/renweizhukov/pytwis","last_synced_at":"2025-04-12T16:31:33.996Z","repository":{"id":57458115,"uuid":"122150388","full_name":"renweizhukov/pytwis","owner":"renweizhukov","description":"A twitter-clone backend using Python and Redis","archived":false,"fork":false,"pushed_at":"2018-06-10T07:37:57.000Z","size":930,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T19:42:55.545Z","etag":null,"topics":["python36","redis","twitter"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/renweizhukov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-20T03:21:04.000Z","updated_at":"2023-02-28T02:08:55.000Z","dependencies_parsed_at":"2022-09-09T23:02:19.198Z","dependency_job_id":null,"html_url":"https://github.com/renweizhukov/pytwis","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renweizhukov%2Fpytwis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renweizhukov%2Fpytwis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renweizhukov%2Fpytwis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renweizhukov%2Fpytwis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renweizhukov","download_url":"https://codeload.github.com/renweizhukov/pytwis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248596517,"owners_count":21130715,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python36","redis","twitter"],"created_at":"2024-12-23T04:13:07.181Z","updated_at":"2025-04-12T16:31:33.963Z","avatar_url":"https://github.com/renweizhukov.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"pytwis\n======\n\n[![Build Status](https://travis-ci.org/renweizhukov/pytwis.svg?branch=master)](https://travis-ci.org/renweizhukov/pytwis)\n\nThis package contains two modules `pytwis` and `pytwis_clt` where \n\n* `pytwis` is a Twitter-toy-clone backend using Redis; \n* `pytwis_clt` is a command-line tool which uses `pytwis` to interact with the Redis database of the Twitter-toy clone.\n\nTo install this package,\n\n```bash\n$ pip install pytwis\n```\n\nNote that \n\n* **This package requires Python 3.6 and later** since it depends on Python 3.6 built-in module [secrets](https://docs.python.org/3/library/secrets.html).\n* There is a breaking change introduced in v0.4.0: the salted password hashes are stored in the Redis database instead of the plain-text passwords, so the Redis database created by the version before v0.4.0 won't work with the version v0.4.0 and after unless a manual database migration is done.\n\nTable of Contents\n=================\n\n   * [1. pytwis](#1-pytwis)\n      * [1.1 Introduction](#11-introduction)\n      * [1.2 Sample usage](#12-sample-usage)\n   * [2. pytwis_clt](#2-pytwis_clt)\n      * [2.1. Connect to Redis](#21-connect-to-redis)\n         * [2.1.1. Connect to the local Redis server at the default port 6379 with no password.](#211-connect-to-the-local-redis-server-at-the-default-port-6379-with-no-password)\n         * [2.1.2. Connect to the local Redis server via the socket file /tmp/redis.sock with password zzzzzz.](#212-connect-to-the-local-redis-server-via-the-socket-file-tmpredissock-with-password-zzzzzz)\n         * [2.1.3 Connect to a remote Redis server with IP = xxx.xxx.xxx.xxx at port yyyy with password zzzzzz.](#213-connect-to-a-remote-redis-server-with-ip--xxxxxxxxxxxx-at-port-yyyy-with-password-zzzzzz)\n      * [2.2. Available commands](#22-available-commands)\n         * [2.2.1. register](#221-register)\n         * [2.2.2. login](#222-login)\n         * [2.2.3. logout](#223-logout)\n         * [2.2.4. changepwd](#224-changepwd)\n         * [2.2.5. userprofile](#225-userprofile)\n         * [2.2.6. follow](#226-follow)\n         * [2.2.7. unfollow](#227-unfollow)\n         * [2.2.8. followers](#228-followers)\n         * [2.2.9. followings](#229-followings)\n         * [2.2.10. post](#2210-post)\n         * [2.2.11. timeline](#2211-timeline)\n         * [2.2.12. tweetsby](#2212-tweetsby)\n         * [2.2.13. exit or \u003ccode\u003equit\u003c/code\u003e](#2213-exit-or-quit)\n   * [3. PEP8](#3-pep8)\n   * [4. Unit test](#4-unit-test)\n   * [5. Documentation](#5-documentation)\n      * [5.1. Sphinx](#51-sphinx)\n      * [5.2. README.rst](#52-readmerst)\n\n# 1. `pytwis`\n\n## 1.1 Introduction\n\nThis module implements the backend for a simplified Twitter clone based on Redis. We follow the Redis tutorial (https://redis.io/topics/twitter-clone) to design the data layout of the Redis database.  \n\nIt supports the following features:\n\n* Register new users\n* Log in/out\n* Change user password\n* Get user profile\n* Post tweets\n* Follower/Following\n* General timeline for anonymous user\n* User timeline\n* Get tweets posted by one user\n\nTODOs:\n\n* Search users\n* Delete a user\n* Recover user password\n* #hashtags\n* @mentions\n* Retweets\n* Replies\n* Conversations\n* Edit/Delete tweets\n* And more\n\n## 1.2 Sample usage\n\nBelow is a sample usage of this module. You can find a more detailed example in the module `pytwis_clt`.\n\n```python\nimport pytwis\n\n# Connect to the Redis server by creating a Pytwis instance. \ntwis = pytwis.Pytwis()\n\n# You may specify the hostname, the port, the database index, and the password of the Redis server as keyword arguments.\ntwis = pytwis.Pytwis(hostname='127.0.0.1', port=6379, db=0, password='password')\n\n# For all the following operations, if succeeded is False, check result['error'] for the error string.\n\n# Register a new user.\nsucceeded, result = twis.register('username', 'password')\n\n# Log into the user. If succeeded is True, result['auth'] will contain the authentication secret.\nsucceeded, result = twis.login('username', 'password')\nif succeeded:\n    auth_secret = result['auth']\n\n# Post a tweet. \nsucceeded, result = twis.post_tweet(auth_secret, 'A tweet')\n\n# Get the general timeline. Note that we are passing an empty authentication secret and '-1' as the second \n# input parameter to get all the tweets in the general timeline. \n# If succeeded is True, result['tweets'] will contain a list of tweets.\nsucceeded, result = twis.get_timeline('', -1)\n\n# Get the user timeline. Note that the second input parameter 100 specifies the maximum number of tweets \n# that will be included in the general timeline.\nsucceeded, result = twis.get_timeline(auth_secret, 100)\n\n# Get the tweets posted by a user. Note that this user may be different from the currently logged-in user.\n# If succeeded is True, result['tweets'] will contain a list of tweets.\nsucceeded, result = twis.get_user_tweets(auth_secret, 'username', -1)\n\n# Follow a user.\nsucceeded, result = twis.follow(auth_secret, 'followee_username')\n\n# Unfollow a user.\nsucceeded, result = twis.unfollow(auth_secret, 'followee_username')\n\n# Get the follower list. If succeeded is True, result['follower_list'] will contain the follower list.\nsucceeded, result = twis.get_followers(auth_secret)\n\n# Get the following list. If succeeded is True, result['following_list'] will contain the following list.\nsucceeded, result = twis.get_followings(auth_secret)\n\n# Change the user password. If succeeded is True, result['auth'] will contain the new authentication secret.\nsucceeded, result = twis.change_password(auth_secret, 'password', 'new_password')\n\n# Get the user profile. If succeeded is True, result['username'] will contain the username, result['password'] \n# will contain the password, and result['auth'] will contain the authentication secret.\nsucceeded, result = twis.get_user_profile(auth_secret)\n\n# Log out of the user.\nsucceeded, result = twis.logout(auth_secret)\n```\n\n# 2. `pytwis_clt`\n\nAfter you install the package, you will be able to launch `pytwis_clt` as a console command. To get the help information,\n\n```bash\n$ pytwis_clt -h\n$ pytwis_clt --help\n```\n\n## 2.1. Connect to Redis\n\n### 2.1.1. Connect to the local Redis server at the default port 6379 with no password.\n    \n```bash\n$ ./pytwis_clt.py \n```\n    \n### 2.1.2. Connect to the local Redis server via the socket file `/tmp/redis.sock` with password zzzzzz. \n\nMake sure that the unixsocket parameter is defined in your redis.conf file. It’s commented out by default.\n    \n```bash\n$ ./pytwis_clt.py -s /tmp/redis.sock -a zzzzzz\n```\n\n### 2.1.3 Connect to a remote Redis server with IP = xxx.xxx.xxx.xxx at port yyyy with password zzzzzz.\n    \n```bash\n$ ./pytwis_clt.py -h xxx.xxx.xxx.xxx -p yyyy -a zzzzzz\n``` \n\n## 2.2. Available commands \n\nAfter successfully connecting to the twitter clone, you can try the following commands in `pytwis_clt`.\n\n### 2.2.1. `register`\n\nRegister a new user `xxxxxx` with password `yyyyyy`.\n\n```bash\n127.0.0.1:6379\u003e register xxxxxx yyyyyy\n```\n\n### 2.2.2. `login`\n\nLog into a user `xxxxxxx` with password `yyyyyy`.\n\n```bash\n127.0.0.1:6379\u003e login xxxxxx yyyyyy\n```\n\n### 2.2.3. `logout`\n\nLog out of the current user.\n\n```bash\n127.0.0.1:6379\u003e logout\n```\n\n### 2.2.4. `changepwd`\n\nChange the password. Assume that the old password is `yyyyyy` and the new password is `zzzzzz`.\n\n```bash\n127.0.0.1:6379\u003e changepwd yyyyyy zzzzzz zzzzzz\n```\n\n### 2.2.5. `userprofile`\n\nGet the profile of the currently logged-in user.\n\n```bash\n127.0.0.1:6379\u003e userprofile\n```\n\n### 2.2.6. `follow`\n\nFollow a user `xxxxxx`.\n\n```bash\n127.0.0.1:6379\u003e follow xxxxxx\n```\n\n### 2.2.7. `unfollow`\n\nUnfollow a user `xxxxxx`.\n\n```bash\n127.0.0.1:6379\u003e unfollow xxxxxx\n```\n\n### 2.2.8. `followers`\n    \nGet the follower list of the current user.\n    \n```bash\n127.0.0.1:6379\u003e followers\n```\n\n### 2.2.9. `followings`\n\nGet the following list of the current user.\n    \n```bash\n127.0.0.1:6379\u003e followings\n```\n\n### 2.2.10. `post`\n\nPost a tweet.\n    \n```bash\n127.0.0.1:6379\u003e post \u003ctweet\u003e\n```\n\n### 2.2.11. `timeline`\n\nGet the general/user timeline. It will return the user timeline if a user is logged in and will return the general timeline otherwise. Also, it will return all the tweets in the timeline if max-tweet-count is not specified.\n\n```bash\n127.0.0.1:6379\u003e timeline [max-tweet-count]\n```\n\n### 2.2.12. `tweetsby`\n\nGet the tweets posted by a user. It will return the tweets posted by the current logged-in user if no username is specified. Also, it will return all the tweets posted by the user if max-tweet-count is not specified.\n\n```bash\n127.0.0.1:6379\u003e tweetsby [username] [max-tweet-count]\n```\n\n### 2.2.13. `exit` or `quit`\n\nExit the console program.\n\n```bash\n127.0.0.1:6379\u003e exit\n127.0.0.1:6379\u003e quit\n```\n\nNote that some of the above commands have to be executed after a successful log-in.\n\n* logout\n* changepassword\n* userprofile\n* follow\n* unfollow\n* followers\n* followings\n* post\n* tweetsby\n\n# 3. PEP8\n\nWe use `pylint` to enforce the Python Style Guide PEP8.\n\n```bash\n$ pylint pytwis\n$ pylint tests\n```\n\nWe have fixed all the convention violations, warnings, and errors in the packages `pytwis` and `tests`. We will address the refactor recommendations made by `pylint` later (see issue #8).\n\n# 4. Unit test\n\nSince this unit test requires a running local Redis server, it is in fact a small integration test. To run the test,\n\n```bash\n$ make test\n```\n\n# 5. Documentation\n\n## 5.1. `Sphinx`\n\nTo generate the `Sphinx` HTML documentation,\n\n```bash\n$ make docs\n```\n\n## 5.2. README.rst\n\nREADME.rst is generated from README.md via `pandoc`.\n\n```bash\n$ pandoc --from=markdown --to=rst --output=README.rst README.md\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenweizhukov%2Fpytwis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenweizhukov%2Fpytwis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenweizhukov%2Fpytwis/lists"}