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

Commit cea5718

Browse files
committed
Added proxy support
Fix for error func
1 parent 06ae824 commit cea5718

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

twint.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import twint
1717
import sys
1818

19-
def error():
19+
def error(error, message):
2020
print("[-] {}: {}".format(error, message))
2121
sys.exit(0)
2222

@@ -32,6 +32,31 @@ def check(args):
3232
error("Contradicting Args", "--users and --tweets cannot be used together.")
3333
if args.csv and args.output is None:
3434
error("Error", "Please specify an output file (Example: -o file.csv).")
35+
if args.proxy_host is not None:
36+
if args.proxy_host.lower() == "tor":
37+
import socks, socket
38+
socks.set_default_proxy(socks.SOCKS5, "localhost", 9050)
39+
socket.socket = socks.socksocket
40+
elif args.proxy_port and args.proxy_type:
41+
if args.proxy_type.lower() == "socks5":
42+
_type = socks.SOCKS5
43+
elif args.proxy_type.lower() == "socks4":
44+
_type = socks.SOCKS4
45+
elif args.proxy_type.lower() == "http":
46+
_type = socks.HTTP
47+
else:
48+
error("Error", "Proxy type allower are: socks5, socks4 and http.")
49+
import socks, socket
50+
socks.set_default_proxy(_type, args.proxy_host, int(args.proxy_port))
51+
socket.socket = socks.socksocket
52+
else:
53+
error("Error", "Please specify --proxy-host, --proxy-port and --proxy-type")
54+
else:
55+
if args.proxy_port or args.proxy_type:
56+
error("Error", "Please specify --proxy-host, --proxy-port and --proxy-type")
57+
58+
59+
3560

3661
def initialize(args):
3762
c = twint.Config()
@@ -62,6 +87,9 @@ def initialize(args):
6287
c.To = args.to
6388
c.All = args.all
6489
c.Debug = args.debug
90+
c.Proxy_type = args.proxy_type
91+
c.Proxy_host = args.proxy_host
92+
c.Proxy_port = args.proxy_port
6593
return c
6694

6795
def options():
@@ -96,6 +124,9 @@ def options():
96124
ap.add_argument("--following", help="Scrape who a person follows.", action="store_true")
97125
ap.add_argument("--favorites", help="Scrape Tweets a user has liked.", action="store_true")
98126
ap.add_argument("--debug", help="Debug mode", action="store_true")
127+
ap.add_argument("--proxy-type", help="Socks5, HTTP, etc.")
128+
ap.add_argument("--proxy-host", help="Proxy hostname or IP")
129+
ap.add_argument("--proxy-port", help="The port of the proxy server")
99130
args = ap.parse_args()
100131
return args
101132

twint/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ class Config:
2828
All = None
2929
Debug = False
3030
Format = None
31+
Proxy_type = None
32+
Proxy_host = None
33+
Proxy_port = None

0 commit comments

Comments
 (0)