Skip to content

Commit 2300a66

Browse files
author
Snosh
authored
release v1.0.3
Fixes
1 parent 273fe66 commit 2300a66

4 files changed

Lines changed: 66 additions & 9 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 SNOSH
3+
Copyright (c) 2020 SNOSH
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

setup.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import os
2-
from distutils.core import setup
1+
from setuptools import setup, find_packages
2+
from os import path
3+
from io import open
34

5+
here = path.abspath(path.dirname(__file__))
46

57
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
68
long_description = f.read()
79

8-
version = '1.0.1'
9-
download_url = 'https://github.com/realSnosh/tenorpy/archive/1.0.1.tar.gz'
10+
version = '1.0.3'
11+
download_url = 'https://github.com/realSnosh/tenorpy/archive/1.0.3.tar.gz'
1012

1113
try:
1214
setup(
@@ -29,11 +31,12 @@
2931
"Programming Language :: Python :: 3.4",
3032
"Programming Language :: Python :: 3.5",
3133
"Programming Language :: Python :: 3.6",
32-
"Programming Language :: Python :: 3.7"
34+
"Programming Language :: Python :: 3.7",
35+
"Programming Language :: Python :: 3.8"
3336

3437
]
3538
)
36-
except:
39+
except Exception:
3740
setup(
3841
name='tenorpy',
3942
version=version,
@@ -53,7 +56,8 @@
5356
"Programming Language :: Python :: 3.4",
5457
"Programming Language :: Python :: 3.5",
5558
"Programming Language :: Python :: 3.6",
56-
"Programming Language :: Python :: 3.7"
59+
"Programming Language :: Python :: 3.7",
60+
"Programming Language :: Python :: 3.8"
5761

5862
]
5963
)

tenorpy/__init__.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,54 @@
1-
from tenorpy.tenorpy import Tenor
1+
import requests
2+
import json
3+
import random
4+
5+
API_KEY = "J5UVWPVIM4A5"
6+
API_ENDPOINT = 'https://api.tenor.co/v1/'
7+
DEFAULT_SEARCH_LIMIT = 25
8+
SAFE_SEARCH = 'off'
9+
10+
11+
class TenorApiException(Exception):
12+
pass
13+
14+
15+
class TenorImage(object):
16+
def __init__(self, data=None):
17+
if data:
18+
self.created = data.get('created')
19+
self.url = data.get('url')
20+
self.tags = data.get('tags')
21+
self.type = data.get('tupe')
22+
self.dims = ""
23+
self.preview = ""
24+
self.size = ""
25+
self.duration = ""
26+
27+
28+
class Tenor(object):
29+
def __init__(self):
30+
self.api_key = API_KEY
31+
32+
def _get(self, **params):
33+
params['api_key'] = self.api_key
34+
35+
response = requests.get('https://api.tenor.co/v1/search', params=params)
36+
37+
results = json.loads(response.text)
38+
39+
return results
40+
41+
def search(self, tag, safesearch=False, limit=None):
42+
params = {'tag': tag}
43+
if safesearch:
44+
params['safesearch'] = safesearch
45+
if limit:
46+
params['limit'] = limit
47+
results = self._get(**params)
48+
return results
49+
50+
def random(self, tag):
51+
search_results = self.search(tag=tag)
52+
random_entry = random.choice(search_results['results'])
53+
gif = random_entry['media'][0]['gif']['url']
54+
return gif
1.92 KB
Binary file not shown.

0 commit comments

Comments
 (0)