Skip to content

Commit 1e4c568

Browse files
committed
Fix bug and publish version 1.1.0
1 parent 8ee4cc4 commit 1e4c568

File tree

5 files changed

+161
-14
lines changed

5 files changed

+161
-14
lines changed

.gitignore

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
131+
videos/
132+
photos/
133+
134+
135+
# VSCode
136+
.vscode/
137+
vscode/

TwiGram.egg-info/PKG-INFO

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
Metadata-Version: 2.1
22
Name: TwiGram
3-
Version: 1.0.2
3+
Version: 1.1.0
44
Summary: Simple python package for download tweet from Twitter
5+
Home-page: UNKNOWN
56
Author: Matin Baloochestani (Matin-B)
67
Author-email: MatiinBaloochestani@Gmail.com
8+
License: UNKNOWN
79
Keywords: python,twitter
10+
Platform: UNKNOWN
811
Classifier: Development Status :: 1 - Planning
912
Classifier: Intended Audience :: Developers
1013
Classifier: Programming Language :: Python :: 3
@@ -43,3 +46,4 @@ from twigram import download
4346
# Get tweet information from Twitter
4447
download("https://twitter.com/i/status/1481722124855169028", show_size=True)
4548
```
49+

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
88
long_description = "\n" + fh.read()
99

10-
VERSION = '1.0.2'
10+
VERSION = '1.1.0'
1111
DESCRIPTION = 'Simple python package for download tweet from Twitter'
1212
LONG_DESCRIPTION = 'Simple python package for download tweet from Twitter'
1313

359 Bytes
Binary file not shown.

twigram/twitter.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import requests
23
import re
34

@@ -41,7 +42,7 @@ def check_content_size(url):
4142
}
4243

4344

44-
def edit_tweet_text(tweet_text: str, entities: dict) -> str:
45+
def edit_tweet_text(tweet_text: str, entities: dict, parent: dict) -> str:
4546
"""
4647
Replace expended urls with their short version
4748
@@ -54,16 +55,16 @@ def edit_tweet_text(tweet_text: str, entities: dict) -> str:
5455
:return: The tweet text with the media url removed.
5556
"""
5657
urls = entities.get("urls")
57-
user_mentions = entities.get("user_mentions")
5858
for url in urls:
5959
expanded_url = url.get("expanded_url")
6060
shorted_url = url.get("url")
6161
tweet_text = tweet_text.replace(shorted_url, expanded_url)
62-
"""
63-
for user in user_mentions:
64-
screen_name = user.get("screen_name")
65-
tweet_text = tweet_text.replace(f"@{screen_name}", "", 1)
66-
"""
62+
with contextlib.suppress(AttributeError):
63+
in_reply_to_screen_name = parent.get("in_reply_to_screen_name")
64+
tweet_text = tweet_text.replace(f"@{in_reply_to_screen_name}", "")
65+
with contextlib.suppress(AttributeError):
66+
parent_user_screen_name = parent.get("user").get("screen_name")
67+
tweet_text = tweet_text.replace(f"@{parent_user_screen_name}", "")
6768
try:
6869
media_url = entities.get("media")[0].get("url")
6970
return tweet_text.replace(f"{media_url}", "").strip()
@@ -95,7 +96,8 @@ def text_tweet_handler(data: dict) -> dict:
9596

9697
tweet_text = data.get("text")
9798
entities = data.get("entities")
98-
tweet_text = edit_tweet_text(tweet_text, entities)
99+
parent = data.get("parent")
100+
tweet_text = edit_tweet_text(tweet_text, entities, parent)
99101

100102
tweet_url = f"https://twitter.com/{owner_username}/status/{tweet_id_str}/"
101103
return {
@@ -141,7 +143,8 @@ def gif_tweet_handler(data: dict) -> dict:
141143

142144
tweet_text = data.get("text")
143145
entities = data.get("entities")
144-
tweet_text = edit_tweet_text(tweet_text, entities)
146+
parent = data.get("parent")
147+
tweet_text = edit_tweet_text(tweet_text, entities, parent)
145148

146149
tweet_url = f"https://twitter.com/{owner_username}/status/{tweet_id_str}/"
147150
return {
@@ -229,7 +232,8 @@ def video_tweet_handler(data: dict, show_size: bool = False) -> dict:
229232

230233
tweet_text = data.get("text")
231234
entities = data.get("entities")
232-
tweet_text = edit_tweet_text(tweet_text, entities)
235+
parent = data.get("parent")
236+
tweet_text = edit_tweet_text(tweet_text, entities, parent)
233237

234238
tweet_url = f"https://twitter.com/{owner_username}/status/{tweet_id_str}/"
235239
return {
@@ -279,7 +283,8 @@ def album_tweet_handler(data: dict) -> dict:
279283

280284
tweet_text = data.get("text")
281285
entities = data.get("entities")
282-
tweet_text = edit_tweet_text(tweet_text, entities)
286+
parent = data.get("parent")
287+
tweet_text = edit_tweet_text(tweet_text, entities, parent)
283288

284289
tweet_url = f"https://twitter.com/{owner_username}/status/{tweet_id_str}/"
285290
return {
@@ -329,7 +334,8 @@ def photo_tweet_handler(data: dict) -> dict:
329334

330335
tweet_text = data.get("text")
331336
entities = data.get("entities")
332-
tweet_text = edit_tweet_text(tweet_text, entities)
337+
parent = data.get("parent")
338+
tweet_text = edit_tweet_text(tweet_text, entities, parent)
333339

334340
tweet_url = f"https://twitter.com/{owner_username}/status/{tweet_id_str}/"
335341
return {

0 commit comments

Comments
 (0)