{"id":24211508,"url":"https://github.com/ramibch/django-tweets","last_synced_at":"2025-03-03T16:21:29.246Z","repository":{"id":191176816,"uuid":"683830176","full_name":"ramibch/django-tweets","owner":"ramibch","description":"An app to manage tweets in a Django project.","archived":false,"fork":false,"pushed_at":"2023-09-10T13:33:57.000Z","size":8312,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-26T09:07:56.391Z","etag":null,"topics":["django","http","python","twitter","twitter-api"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/django-tweets/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ramibch.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-27T20:40:19.000Z","updated_at":"2023-09-07T17:11:53.000Z","dependencies_parsed_at":"2024-12-09T23:35:14.713Z","dependency_job_id":"7da40883-220e-4083-b87a-1c1c500c5188","html_url":"https://github.com/ramibch/django-tweets","commit_stats":null,"previous_names":["ramiboutas/django-tweets","ramibch/django-tweets"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramibch%2Fdjango-tweets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramibch%2Fdjango-tweets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramibch%2Fdjango-tweets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramibch%2Fdjango-tweets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ramibch","download_url":"https://codeload.github.com/ramibch/django-tweets/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241696136,"owners_count":20004748,"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":["django","http","python","twitter","twitter-api"],"created_at":"2025-01-14T02:35:36.425Z","updated_at":"2025-03-03T16:21:29.216Z","avatar_url":"https://github.com/ramibch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# django-tweets\n[\u003cimg align=\"center\"  width=\"100%\"  src=\"images/logo_large.png\"\u003e](https://twitter.com/django_tweets)\n\nCreate and delete tweets in a Django project.\n\nThis packages takes the advantage of the [tweepy](https://www.tweepy.org/) functionalities to connect it to a Django Backend.\n\nThe tweets objects can have media files as well.\n\n\n\n\n## Set up\n\n\n### Twitter Account\n\n1. Make sure you have a Twitter account.\n2. Go to the [Twitter Developer Portal](https://developer.twitter.com/en/portal/dashboard).\n3. Create a Project and an App\n4. Make sure your App has read and write permissions.\n5. Genenerate the necessary secrets and token.\n\n\n### django-tweets\n\n\n1. Install from PyPI\n```\npython -m pip install django-tweets\n```\n\n2. Add the package to your settins INSTALLED_APPS\n\n```python\n\nINSTALLED_APPS = [\n    ...\n    \"django_tweets\",\n    ...\n]\n\n```\n\n\n\n\n3. Add the following settings to your Django project.\n\n| Django setting              | Description                                                                 | Required |\n|-----------------------------|-----------------------------------------------------------------------------|----------|\n| TWITTER_API_KEY             | Twitter API OAuth 1.0a Consumer Key                                         | Yes      |\n| TWITTER_API_KEY_SECRET      | Twitter API OAuth 1.0a Consumer Secret                                      | Yes      |\n| TWITTER_BEARER_TOKEN        | Twitter API OAuth 2.0 Bearer Token / Access Token                           | Yes      |\n| TWITTER_ACCESS_TOKEN        | Twitter API OAuth 1.0a Access Token                                         | Yes      |\n| TWITTER_ACCESS_TOKEN_SECRET | Twitter API OAuth 1.0a Access Token Secret                                  | Yes      |\n| DJANGO_TWEETS_SYNC_DELETE   | Synchronize object deletion with Twitter API. This is activated by default. | No       |\n| TWITTER_USERNAME            | Useful for accessing to the url of a Tweet object                           | No       |\n\n\n\nExample:\n\n```python\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\n\n...\n\n############################## django-tweets ##############################\n# username\nTWITTER_USERNAME = \"django_tweets\" # https://twitter.com/django_tweets\n# Consumer Keys\nTWITTER_API_KEY = os.environ.get(\"TWITTER_API_KEY\")\nTWITTER_API_KEY_SECRET = os.environ.get(\"TWITTER_API_KEY_SECRET\")\n# Authentication Tokens\nTWITTER_BEARER_TOKEN = os.environ.get(\"TWITTER_BEARER_TOKEN\")\nTWITTER_ACCESS_TOKEN = os.environ.get(\"TWITTER_ACCESS_TOKEN\")\nTWITTER_ACCESS_TOKEN_SECRET = os.environ.get(\"TWITTER_ACCESS_TOKEN_SECRET\")\n# OAuth 2.0 Client ID and Client Secret\nTWITTER_CLIENT_ID = os.environ.get(\"TWITTER_CLIENT_ID\")\nTWITTER_CLIENT_SECRET = os.environ.get(\"TWITTER_CLIENT_SECRET\")\n\n```\n\n4. Run migrations\n\n```\npython manage.py migrate\n\n```\n\n\n## Usage\n\n\n### Create a simple tweet\n\n```python\n\nfrom django_tweets.models import Tweet\n\n# create a tweet in the db\ntweet = Tweet.objects.create(text=\"Hi, this is my tweet using django-tweets and tweepy\")\n\n# publish it\ntweet.publish()\n\n```\n### Create a tweet with a media file\n\n```python\nfrom pathlib import Path\nfrom django.core.files.base import ContentFile\nfrom django_tweets.models import Tweet, TweetFile\n\n# create a media file\npath = Path(\"path/to/my/file.jpg\")\n\nwith open(path, \"rb\") as f:\n    f.seek(0)\n    contents = f.read()\n\ntweet_file = TweetFile.objects.create(title=\"nice photo\")\ntweet_file.file.save(path.name, ContentFile(contents))\n# upload to Twitter\ntweet_file = tweet_file.upload()\n\n# create a tweet in the db\ntweet = Tweet.objects.create(text=\"My tweet with a file\")\n\n# add the media file to the tweet object\ntweet.files.add(tweet_file)\n\n# publish it\ntweet.publish()\n\n```\n\n### Usage in the admin\n\n![Django admin](images/admin.png)\n\n* Use [http://127.0.0.1:8000/admin/django_tweets/tweet/](http://127.0.0.1:8000/admin/django_tweets/tweet/) to create a Tweet object\n* Use [http://127.0.0.1:8000/admin/django_tweets/tweetpublication/](http://127.0.0.1:8000/admin/django_tweets/tweetpublication/) to link a Tweet object to publish it.\n\nSimilarly works with the `TweetFile` and `TweetFileUpload` models.\n\n\n\u003c!--- this takes to much space in the README...\n\n## Questions\n* How Can I get the read and write permission for my app?\nAnswer:\n1. In the [Twitter Developer Portal](https://developer.twitter.com/en/portal/dashboard), click on gear icon of the project app\n\n![Gear icon app settings](images/app_settings.png)\n\n\n2. Then go _User authentication settings_ and click on the _Edit_ button.\n\n![Edit user auth settings](images/edit_permissions.png)\n\n\n3. Configure the the form and submit.\n\n![User authentication settings](images/app_user_permissions.png)\n--\u003e\n\n\n\n## About\n\n[🐣 django_tweets](https://twitter.com/django_tweets)\n\n©Django is a registered trademark of the Django Software Foundation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framibch%2Fdjango-tweets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Framibch%2Fdjango-tweets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framibch%2Fdjango-tweets/lists"}