Skip to content
This repository was archived by the owner on Apr 26, 2023. It is now read-only.

Commit 8b80763

Browse files
committed
added module support 🔥
1 parent b2fe64b commit 8b80763

File tree

7 files changed

+188
-54
lines changed

7 files changed

+188
-54
lines changed

README.md

+90-24
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,120 @@
1-
<h1>Tweeds - Twitter Scraping Tool</h1>
2-
<p align="center"><img src="https://media.tenor.com/Xrt-ty39PfEAAAAC/elon-musk-smoke.gif"/></p>
1+
# Tweeds - Twitter Scraping Tool
32

4-
Scrape tweets from any Twitter user profile. Twitter API alternative to scrape Twitter hashtags, threads, images, videos, statistics,
5-
and Twitter history. Export data in JSON and CSV format. This project enables you to extract large amounts of data from Twitter.
6-
It lets you do much more than the Twitter API, because it doesn't have rate limits and you don't even need to have a **Twitter account, a registered app,
3+
<p align="center">
4+
<img src="https://media.tenor.com/Xrt-ty39PfEAAAAC/elon-musk-smoke.gif"/>
5+
</p>
6+
7+
Scrape tweets from any Twitter user profile. Twitter API alternative to scrape Twitter hashtags, threads, images, videos, statistics,
8+
and Twitter history. Export data in JSON and CSV format. This project enables you to extract large amounts of data from Twitter.
9+
It lets you do much more than the Twitter API, because it doesn't have rate limits and you don't even need to have a **Twitter account, a registered app,
710
or Twitter API key.**
811

912
### Do not forget to star this project.🌟 😍
1013

1114
## 💡 Features
12-
- No API Key required
15+
16+
- No API Key required
1317
- No Limit
1418
- No Authentication required
1519
- Get tweets from specific user
1620
- JSON and CSV export for further Data Analysis
1721
- And the best part it is OpenSource 😉
1822

1923
## ✔️ Requirements
24+
2025
- Python >= 3.9
2126

22-
## ⚙ Installation
27+
## ⚙ Installation
28+
2329
```bash
2430
pip install tweeds
2531
```
2632

2733
## 💃 Usage
28-
![Basic](https://files.catbox.moe/ph7txh.png)
2934

30-
## 📙 Example
31-
Getting tweets from a specific user
32-
```Bash
33-
tweeds -u TheNameisYash --json yashtweets.json
34-
```
35-
Getting tweets from a search term or #hastag
3635
```Bash
37-
tweeds -s "#Messi" --json messigoat.json --minLikes 10000 --limit 100
38-
```
39-
Getting tweets from a specific region (.ie Paris)
40-
```Bash
41-
tweeds -s "coffee sucks" --near Paris --limit 100
36+
achyuthjoism-MBP ~ %tweeds
37+
38+
████████╗░██╗░░░░░░░██╗███████╗███████╗██████╗░░██████╗
39+
╚══██╔══╝░██║░░██╗░░██║██╔════╝██╔════╝██╔══██╗██╔════╝
40+
░░░██║░░░░╚██╗████╗██╔╝█████╗░░█████╗░░██║░░██║╚█████╗░
41+
░░░██║░░░░░████╔═████║░██╔══╝░░██╔══╝░░██║░░██║░╚═══██╗
42+
░░░██║░░░░░╚██╔╝░╚██╔╝░███████╗███████╗██████╔╝██████╔╝
43+
░░░╚═╝░░░░░░╚═╝░░░╚═╝░░╚══════╝╚══════╝╚═════╝░╚═════╝░
44+
45+
by Achyuth Jois M
46+
47+
usage: tweeds [-h] [-u U] [-s S] [--since SINCE] [--until UNTIL] [--limit LIMIT] [--near NEAR] [--geocode GEOCODE]
48+
[--year YEAR] [--today] [--verified] [--link LINK] [--videos] [--images] [--media] [--minLikes MINLIKES]
49+
[--minRetweets MINRETWEETS] [--minReplies MINREPLIES] [--json JSON] [--csv CSV] [--silent]
50+
51+
Scrape twitter user tweets
52+
53+
options:
54+
-h, --help show this help message and exit
55+
-u U Users Tweets you want to scrape.
56+
-s S Search for Tweets containing this word or phrase.
57+
--since SINCE Filter Tweets sent since date (Example: "2017-12-27 20:30:15" or 2017-12-27).
58+
--until UNTIL Filter Tweets sent until date (Example: "2017-12-27 20:30:15" or 2017-12-27).
59+
--limit LIMIT Number of Tweets to pull
60+
--near NEAR Find tweets near a particular location
61+
--geocode GEOCODE Search for geocoded Tweets.
62+
--year YEAR Filter Tweets before specified year.
63+
--today Filter Tweets from today
64+
--verified Display Tweets only from verified users (Use with -s).
65+
--links LINK Exclude tweets containing one or more links.
66+
--videos Display only Tweets with videos.
67+
--images Display only Tweets with images.
68+
--media Display Tweets with only images or videos.
69+
--minLikes MINLIKES Minimun likes for the tweet
70+
--minRetweets MINRETWEETS
71+
Minimun retweets for the tweet
72+
--minReplies MINREPLIES
73+
Minimun replies for the tweet
74+
--json JSON File to write the JSON output to.
75+
--csv CSV To store the output in CSV
76+
--silent Dont print the tweets(Only works while taking an output!)[Type anything]
77+
78+
achyuthjoism-MBP ~ %
79+
4280
```
43-
A some more simple examples to help you understand the basics:
4481
45-
- `tweeds -u username` - Scrape all the Tweets of a *user* (doesn't include **retweets** but includes **replies**).
46-
- `tweeds -u username -s pineapple` - Scrape all Tweets from the *user*'s timeline containing _pineapple_.
47-
- `tweeds -s pineapple` - Collect every Tweet containing *pineapple* from everyone's Tweets.
82+
## 📙 Example
83+
84+
### CLI Example
85+
86+
Some simple examples to help you understand the basics:
87+
88+
- `tweeds -u username` - Scrape all the Tweets of a _user_ (doesn't include **retweets** but includes **replies**).
89+
- `tweeds -u username -s pineapple` - Scrape all Tweets from the _user_'s timeline containing _pineapple_.
90+
- `tweeds -s pineapple` - Collect every Tweet containing _pineapple_ from everyone's Tweets.
4891
- `tweeds -u username --since "2015-12-20 20:30:15"` - Collect Tweets that were tweeted since 2015-12-20 20:30:15.
4992
- `tweeds -u username --since 2015-12-20` - Collect Tweets that were tweeted since 2015-12-20 00:00:00.
50-
- `tweeds -u username --csv file.csv` - Scrape Tweets and save as a csv file.
93+
- `tweeds -s "Rocking Star Yash" --verified` - Display Tweets by verified users that Tweeted about Rocking Star Yash.
94+
- `tweeds -geocode "48.880048,2.385939,1km" --csv paris.csv --limit 10` - Scrape Tweets from a radius of 1km around a place in Paris and export them to a csv file.
95+
- `tweeds -u username --images` - Scrape Tweets from a user containing only images.
96+
- `tweeds -u username --videos` - Scrape Tweets from a user containing only videos.
97+
- `tweeds -u username --media` - Scarape Tweets from a user containing both images and videos.
98+
- `tweeds -u username --links` - Scrape Tweets from a user which excludes links.
5199
- `tweeds -u username --json file.json` - Scrape Tweets and save as a json file.
100+
- `tweeds -u username --csv file.csv` - Scrape Tweets and save as a csv file.
101+
102+
### Module Example
103+
104+
Now Tweed can be used as a module and allows custom formatting.
105+
Example:
106+
107+
```python
108+
import tweeds
109+
110+
query = tweeds.Query()
111+
112+
query.search = "Yash Boss"
113+
query.limit = 10
114+
query.verified = True
115+
116+
tweeds.search(query)
117+
```
52118
53119
**Have fun 🥰💞**
54120

tweeds/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from tweeds.query import Query
2+
from tweeds.tweet_scrape import search

tweeds/classes/__init__.py

Whitespace-only changes.

tweeds/classes/query.py

-20
This file was deleted.

tweeds/main.py

+43-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import argparse as ap
22
import sys
3-
import tweeds.classes.query as query
4-
import tweeds.tweet_scrape as ts
3+
from tweeds.query import Query
4+
from tweeds.tweet_scrape import search
55

66

77
def banner():
88
print("""
9-
▀█▀ █░█░█ █ ▀█▀ ▀█▀ █▀▀ █▀█   █▀█ █▀ █ █▄░█ ▀█▀
10-
░█░ ▀▄▀▄▀ █ ░█░ ░█░ ██▄ █▀▄   █▄█ ▄█ █ █░▀█ ░█░
9+
████████╗░██╗░░░░░░░██╗███████╗███████╗██████╗░░██████╗
10+
╚══██╔══╝░██║░░██╗░░██║██╔════╝██╔════╝██╔══██╗██╔════╝
11+
░░░██║░░░░╚██╗████╗██╔╝█████╗░░█████╗░░██║░░██║╚█████╗░
12+
░░░██║░░░░░████╔═████║░██╔══╝░░██╔══╝░░██║░░██║░╚═══██╗
13+
░░░██║░░░░░╚██╔╝░╚██╔╝░███████╗███████╗██████╔╝██████╔╝
14+
░░░╚═╝░░░░░░╚═╝░░░╚═╝░░╚══════╝╚══════╝╚═════╝░╚═════╝░
1115
1216
by Achyuth Jois M
1317
""")
@@ -17,7 +21,7 @@ def banner():
1721

1822

1923
def config(args: ap.Namespace):
20-
c = query.Query()
24+
c = Query()
2125
c.search = args.s
2226
c.username = args.u
2327
c.limit = args.limit
@@ -30,13 +34,20 @@ def config(args: ap.Namespace):
3034
c.minReplies = args.minReplies
3135
c.minRetweets = args.minRetweets
3236
c.silent = args.silent
37+
c.verified = args.verified
38+
c.geoCode = args.geocode
39+
c.links = args.links
40+
c.videos = args.videos
41+
c.images = args.images
42+
c.media = args.media
43+
c.year = args.year
3344

3445
return c
3546

3647

3748
def process_args(args: ap.Namespace):
3849
q = config(args)
39-
ts.search(q)
50+
search(q)
4051

4152

4253
def main():
@@ -57,6 +68,31 @@ def main():
5768
parse.add_argument(
5869
'--near', type=str, help="Find tweets near a particular location"
5970
)
71+
parse.add_argument(
72+
'--geocode', type=str, help="Search for geocoded Tweets."
73+
)
74+
parse.add_argument(
75+
'--year', type=int, help="Filter Tweets before specified year."
76+
)
77+
parse.add_argument(
78+
'--today', help="Filter Tweets from today", action='store_true'
79+
)
80+
parse.add_argument(
81+
'--verified', help="Display Tweets only from verified users (Use with -s).", action='store_true'
82+
)
83+
parse.add_argument(
84+
'--links', help="Exclude tweets containing one or more links.", action='store_true'
85+
)
86+
parse.add_argument(
87+
"--videos", help="Display only Tweets with videos.", action='store_true'
88+
)
89+
parse.add_argument(
90+
"--images", help="Display only Tweets with images.", action='store_true'
91+
)
92+
parse.add_argument(
93+
"--media", help="Display Tweets with only images or videos.", action='store_true'
94+
)
95+
6096
parse.add_argument(
6197
'--minLikes', type=int, help="Minimun likes for the tweet"
6298
)
@@ -72,7 +108,7 @@ def main():
72108
'--csv', type=str, help="To store the output in CSV"
73109
)
74110
parse.add_argument(
75-
'--silent', type=str, help="Don't print the tweets(Only works while taking an output!)[Type anything]"
111+
'--silent', help="Don't print the tweets(Only works while taking an output!)[Type anything]", action='store_true'
76112
)
77113

78114
args = parse.parse_args(args=None if sys.argv[1:] else ['--help'])

tweeds/query.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import dataclasses
2+
from typing import Optional
3+
4+
5+
@dataclasses.dataclass
6+
class Query:
7+
"""
8+
Class used to query in twitter
9+
"""
10+
username: Optional[str] = None
11+
search: Optional[str] = None
12+
since: Optional[str] = None
13+
until: Optional[str] = None
14+
json: Optional[str] = None
15+
limit: Optional[int] = None
16+
near: Optional[str] = None
17+
minLikes: Optional[int] = None
18+
csv: Optional[str] = None
19+
minReplies: Optional[int] = None
20+
minRetweets: Optional[int] = None
21+
silent: bool = False
22+
verified: bool = False
23+
geoCode: Optional[str] = None
24+
links: bool = False
25+
videos: bool = False
26+
images: bool = False
27+
media: bool = False
28+
year: Optional[int] = None
29+
today: bool = False
30+
31+
def __init__(self) -> None:
32+
pass

tweeds/tweet_scrape.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import snscrape.modules.twitter as api
22
import pandas as pd
33
import json
4-
import tweeds.classes.query as query
4+
from tweeds.query import Query
5+
from datetime import date
56

67

78
def make_json(data, jsonFilePath):
@@ -32,13 +33,19 @@ def toOBJ(tweet: api.Tweet) -> object:
3233
}
3334

3435

35-
def search(q: query.Query) -> None:
36+
def search(q: Query) -> None:
37+
"""Print tweets"""
3638
query = ""
3739

3840
if q.search:
3941
query += f"{q.search} "
4042
if q.username:
4143
query += f"(from:{q.username}) "
44+
if q.today:
45+
today = date.today().strftime("%Y/%m/%d")
46+
query += f"until:{today}"
47+
if q.year:
48+
query += f"until:{q.year}-01-01 "
4249
if q.until:
4350
query += f"until:{q.until} "
4451
if q.since:
@@ -51,7 +58,18 @@ def search(q: query.Query) -> None:
5158
query += f" min_retweets:{q.minRetweets} "
5259
if q.near:
5360
query += f"near:{q.near} "
54-
61+
if q.geoCode:
62+
query += f"geocode:{q.geoCode} "
63+
if q.verified:
64+
query += f"filter:verified "
65+
if q.media:
66+
query += f"filter:media "
67+
if q.videos and not q.media and not q.images:
68+
query += f"filter:native_video "
69+
if q.images and not q.media and not q.videos:
70+
query += f"filter:images "
71+
if q.links:
72+
query += "-filter:links "
5573
jsonObj = {}
5674
csvObj = []
5775

0 commit comments

Comments
 (0)