├── setup.cfg ├── MANIFEST ├── .github ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── FUNDING.yml └── workflows │ └── python-publish.yml ├── LICENSE ├── README.md ├── setup.py ├── TenGiphPy └── __init__.py └── CODE_OF_CONDUCT.md /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md -------------------------------------------------------------------------------- /MANIFEST: -------------------------------------------------------------------------------- 1 | # file GENERATED by distutils, do NOT edit 2 | setup.cfg 3 | setup.py 4 | tenorpy\__init__.py 5 | tenorpy\tenorpy.py 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. Windows] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | - Py Ver and TenGiphPy Ver 31 | 32 | **Additional context** 33 | Add any other context about the problem here. 34 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: miditkl # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: miditkl # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: ['buymeacoffee.com/miditkl'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 SNOSH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /.github/workflows/python-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will upload a Python Package using Twine when a release is created 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Upload Python Package 10 | 11 | on: 12 | release: 13 | types: [published] 14 | 15 | permissions: 16 | contents: read 17 | 18 | jobs: 19 | deploy: 20 | 21 | runs-on: ubuntu-latest 22 | 23 | steps: 24 | - uses: actions/checkout@v3 25 | - name: Set up Python 26 | uses: actions/setup-python@v3 27 | with: 28 | python-version: '3.x' 29 | - name: Install dependencies 30 | run: | 31 | python -m pip install --upgrade pip 32 | pip install build 33 | - name: Build package 34 | run: python -m build 35 | - name: Publish package 36 | uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 37 | with: 38 | user: __token__ 39 | password: ${{ secrets.PYPI_API_TOKEN }} 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | TenGiphPy is a Python wrapper for the Tenor and Giphy API. 2 | 3 | Installation 4 | =============== 5 | Clone Repository: ``python3 setup.py install`` 6 | 7 | Install with pip: ``python3 -m pip install TenGiphPy`` 8 | 9 | Update with pip: ``python3 -m pip install -U TenGiphPy`` 10 | 11 | Usage 12 | ===== 13 | **GIF Endpoints** 14 | 15 | To use: 16 | 17 | ```python 18 | 19 | import TenGiphPy 20 | t = TenGiphPy.Tenor(token='APITOKEN') 21 | g = TenGiphPy.Giphy(token='APITOKEN') 22 | 23 | #sync 24 | print(t.random("GIFTAG")) 25 | print(g.random(tag="GIFTAG")['data']['images']['downsized_large']['url']) 26 | 27 | # Will return synchronously a random GIF with the tag "GIFTAG" 28 | 29 | #async 30 | import asyncio 31 | print(asyncio.run(t.arandom('GIFTAG'))) 32 | print((asyncio.run(g.arandom(tag="GIFTAG"))['data']['images']['downsized_large']['url'])) 33 | 34 | # Will return asynchronously a random GIF with the tag "GIFTAG" 35 | 36 | ``` 37 | 38 | Get API Tokens 39 | ============== 40 | [Tenor Developer Portal](https://tenor.com/developer/dashboard) 41 | 42 | [Giphy Developer Portal](https://developers.giphy.com/) 43 | 44 | Examples 45 | ========= 46 | [Click here, if you want a sample script for the discord.py library](https://gist.github.com/realSnosh/3eae65975e09e3f60fbeeee393054cf2) 47 | 48 | [Click here, if you want a sample script for the discord.py library in an asynchronous version](https://gist.github.com/realSnosh/735adb1660823261a881f4b17276cd9e) 49 | 50 | _If you are on pypi and this readme is incorrect showed, [click here](https://github.com/realSnosh/TenGiphPy) to view the GitHub version!_ -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from os import path 3 | from io import open 4 | 5 | here = path.abspath(path.dirname(__file__)) 6 | 7 | with open(path.join(here, 'README.md'), encoding='utf-8') as f: 8 | long_description = f.read() 9 | 10 | package_name = 'TenGiphPy' 11 | author = 'Snosh' 12 | version = '2.5.0' 13 | desc = 'API Wrapper for the Gif library Tenor and Giphy. Join my server: https://discord.gg/uFdVUMH' 14 | kw = 'giphy, tenor, python, python3, api, wrapper, alphasnosh, snosh' 15 | download_url = 'https://github.com/realSnosh/TenGiphPy/archive/2.5.0.tar.gz' 16 | requirements = ['requests'] 17 | classifiers = [ 18 | "Intended Audience :: Developers", 19 | "Topic :: Software Development :: Build Tools", 20 | "License :: OSI Approved :: MIT License", 21 | "Programming Language :: Python :: 3.6", 22 | "Programming Language :: Python :: 3.7", 23 | "Programming Language :: Python :: 3.8", 24 | "Programming Language :: Python :: 3.9" 25 | ] 26 | 27 | 28 | try: 29 | setup( 30 | name=package_name, 31 | version=version, 32 | author=author, 33 | description=desc, 34 | long_description=long_description, 35 | license='MIT', 36 | keywords=kw, 37 | url='https://github.com/realSnosh/TenGiphPy', 38 | download_url=download_url, 39 | packages=[f'{package_name}'], 40 | install_requires=requirements, 41 | classifiers=classifiers 42 | ) 43 | except Exception: 44 | setup( 45 | name=package_name, 46 | version=version, 47 | author=author, 48 | description=desc, 49 | license='MIT', 50 | keywords=kw, 51 | url='https://github.com/realSnosh/TenGiphPy', 52 | download_url=download_url, 53 | packages=[f'{package_name}'], 54 | install_requires=requirements, 55 | classifiers=classifiers 56 | ) 57 | -------------------------------------------------------------------------------- /TenGiphPy/__init__.py: -------------------------------------------------------------------------------- 1 | import functools 2 | import requests 3 | import json 4 | import random 5 | from urllib.parse import urlencode 6 | 7 | 8 | class Giphy(object): 9 | def __init__(self, token): 10 | self.token = token 11 | self.base = f"https://api.giphy.com/v1/gifs" 12 | 13 | def Post(self, endpoint=None, **kwargs): 14 | if endpoint: 15 | if kwargs: 16 | if "fmt" in kwargs: 17 | del (kwargs["fmt"]) 18 | params = urlencode(kwargs) 19 | url = f"{self.base}{endpoint}?api_key={self.token}&{params}" 20 | else: 21 | url = f"{self.base}{endpoint}?api_key={self.token}" 22 | else: 23 | if "fmt" in kwargs: 24 | kwargs["fmt"] = "json" 25 | 26 | params = urlencode(kwargs) 27 | url = f"{self.base}?api_key={self.token}&{params}" 28 | result = requests.get(url) 29 | return result.json() 30 | 31 | def gif_by_id(self, id): 32 | return self.Post(endpoint=f"/{id}") 33 | 34 | def gifs_by_id(self, ids): 35 | return self.Post(ids=','.join(ids)) 36 | 37 | def __getattr__(self, attr): 38 | endpoint = f"/{attr}" 39 | return functools.partial(self.Post, endpoint) 40 | 41 | async def arandom(self, tag): 42 | return self.Post(endpoint=f'/random', tag=tag) 43 | 44 | 45 | class TenorImage(object): 46 | def __init__(self, data=None): 47 | if data: 48 | self.created = data.get('created') 49 | self.url = data.get('url') 50 | self.tags = data.get('tags') 51 | self.type = data.get('tupe') 52 | self.dims = "" 53 | self.preview = "" 54 | self.size = "" 55 | self.duration = "" 56 | 57 | 58 | class Tenor(object): 59 | def __init__(self, token): 60 | self.api_key = token 61 | 62 | def _get(self, **params): 63 | params['key'] = self.api_key 64 | 65 | response = requests.get('https://g.tenor.com/v2/search', params=params) 66 | 67 | results = json.loads(response.content) 68 | 69 | return results 70 | 71 | def search(self, tag, safesearch=False, limit=None): 72 | params = {'q': tag} 73 | if safesearch: 74 | params['contentfilter'] = safesearch 75 | if limit: 76 | params['limit'] = limit 77 | results = self._get(**params) 78 | return results 79 | 80 | def random(self, tag): 81 | search_results = self.search(tag=tag) 82 | random_entry = random.choice(search_results['results']) 83 | gif = random_entry['media_formats']['gif']['url'] 84 | return gif 85 | 86 | async def asearch(self, tag, safesearch=False, limit=None): 87 | params = {'q': tag} 88 | if safesearch: 89 | params['contentfilter'] = safesearch 90 | if limit: 91 | params['limit'] = limit 92 | results = self._get(**params) 93 | return results 94 | 95 | async def arandom(self, tag): 96 | search_results = self.search(tag=tag) 97 | random_entry = random.choice(search_results['results']) 98 | gif = random_entry['media_formats']['gif']['url'] 99 | return gif 100 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Citizen Code of Conduct 2 | 3 | ## 1. Purpose 4 | 5 | A primary goal of TenGiphPy is to be inclusive to the largest number of contributors, with the most varied and diverse backgrounds possible. As such, we are committed to providing a friendly, safe and welcoming environment for all, regardless of gender, sexual orientation, ability, ethnicity, socioeconomic status, and religion (or lack thereof). 6 | 7 | This code of conduct outlines our expectations for all those who participate in our community, as well as the consequences for unacceptable behavior. 8 | 9 | We invite all those who participate in TenGiphPy to help us create safe and positive experiences for everyone. 10 | 11 | ## 2. Open [Source/Culture/Tech] Citizenship 12 | 13 | A supplemental goal of this Code of Conduct is to increase open [source/culture/tech] citizenship by encouraging participants to recognize and strengthen the relationships between our actions and their effects on our community. 14 | 15 | Communities mirror the societies in which they exist and positive action is essential to counteract the many forms of inequality and abuses of power that exist in society. 16 | 17 | If you see someone who is making an extra effort to ensure our community is welcoming, friendly, and encourages all participants to contribute to the fullest extent, we want to know. 18 | 19 | ## 3. Expected Behavior 20 | 21 | The following behaviors are expected and requested of all community members: 22 | 23 | * Participate in an authentic and active way. In doing so, you contribute to the health and longevity of this community. 24 | * Exercise consideration and respect in your speech and actions. 25 | * Attempt collaboration before conflict. 26 | * Refrain from demeaning, discriminatory, or harassing behavior and speech. 27 | * Be mindful of your surroundings and of your fellow participants. Alert community leaders if you notice a dangerous situation, someone in distress, or violations of this Code of Conduct, even if they seem inconsequential. 28 | * Remember that community event venues may be shared with members of the public; please be respectful to all patrons of these locations. 29 | 30 | ## 4. Unacceptable Behavior 31 | 32 | The following behaviors are considered harassment and are unacceptable within our community: 33 | 34 | * Violence, threats of violence or violent language directed against another person. 35 | * Sexist, racist, homophobic, transphobic, ableist or otherwise discriminatory jokes and language. 36 | * Posting or displaying sexually explicit or violent material. 37 | * Posting or threatening to post other people's personally identifying information ("doxing"). 38 | * Personal insults, particularly those related to gender, sexual orientation, race, religion, or disability. 39 | * Inappropriate photography or recording. 40 | * Inappropriate physical contact. You should have someone's consent before touching them. 41 | * Unwelcome sexual attention. This includes, sexualized comments or jokes; inappropriate touching, groping, and unwelcomed sexual advances. 42 | * Deliberate intimidation, stalking or following (online or in person). 43 | * Advocating for, or encouraging, any of the above behavior. 44 | * Sustained disruption of community events, including talks and presentations. 45 | 46 | ## 5. Weapons Policy 47 | 48 | No weapons will be allowed at TenGiphPy events, community spaces, or in other spaces covered by the scope of this Code of Conduct. Weapons include but are not limited to guns, explosives (including fireworks), and large knives such as those used for hunting or display, as well as any other item used for the purpose of causing injury or harm to others. Anyone seen in possession of one of these items will be asked to leave immediately, and will only be allowed to return without the weapon. Community members are further expected to comply with all state and local laws on this matter. 49 | 50 | ## 6. Consequences of Unacceptable Behavior 51 | 52 | Unacceptable behavior from any community member, including sponsors and those with decision-making authority, will not be tolerated. 53 | 54 | Anyone asked to stop unacceptable behavior is expected to comply immediately. 55 | 56 | If a community member engages in unacceptable behavior, the community organizers may take any action they deem appropriate, up to and including a temporary ban or permanent expulsion from the community without warning (and without refund in the case of a paid event). 57 | 58 | ## 7. Reporting Guidelines 59 | 60 | If you are subject to or witness unacceptable behavior, or have any other concerns, please notify a community organizer as soon as possible. @realSnosh. 61 | 62 | discord.gg/uFdVUMH 63 | 64 | Additionally, community organizers are available to help community members engage with local law enforcement or to otherwise help those experiencing unacceptable behavior feel safe. In the context of in-person events, organizers will also provide escorts as desired by the person experiencing distress. 65 | 66 | ## 8. Addressing Grievances 67 | 68 | If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify realSnosh on discord.gg/uFdVUMH with a concise description of your grievance. Your grievance will be handled in accordance with our existing governing policies. 69 | 70 | 71 | 72 | ## 9. Scope 73 | 74 | We expect all community participants (contributors, paid or otherwise; sponsors; and other guests) to abide by this Code of Conduct in all community venues--online and in-person--as well as in all one-on-one communications pertaining to community business. 75 | 76 | This code of conduct and its related procedures also applies to unacceptable behavior occurring outside the scope of community activities when such behavior has the potential to adversely affect the safety and well-being of community members. 77 | 78 | ## 10. Contact info 79 | 80 | @realSnosh discord.gg/uFdVUMH 81 | 82 | ## 11. License and attribution 83 | 84 | The Citizen Code of Conduct is distributed by [Stumptown Syndicate](http://stumptownsyndicate.org) under a [Creative Commons Attribution-ShareAlike license](http://creativecommons.org/licenses/by-sa/3.0/). 85 | 86 | Portions of text derived from the [Django Code of Conduct](https://www.djangoproject.com/conduct/) and the [Geek Feminism Anti-Harassment Policy](http://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy). 87 | 88 | _Revision 2.3. Posted 6 March 2017._ 89 | 90 | _Revision 2.2. Posted 4 February 2016._ 91 | 92 | _Revision 2.1. Posted 23 June 2014._ 93 | 94 | _Revision 2.0, adopted by the [Stumptown Syndicate](http://stumptownsyndicate.org) board on 10 January 2013. Posted 17 March 2013._ 95 | --------------------------------------------------------------------------------