Skip to content

Commit 9ecdc65

Browse files
feat : internet function added
1 parent 71bce99 commit 9ecdc65

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

.idea/workspace.xml

Lines changed: 21 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import requests
22
import sys
3+
import socket
34
def url_maker_following(Name,page_number):
45
return "https://github.com/"+Name+"?page="+str(page_number)+"&tab=following"
56
def url_maker_follower(Name,page_number):
@@ -55,6 +56,29 @@ def following_list_gen(follower_name):
5556
following_list.extend(temp_list)
5657
return following_list
5758

59+
def internet(host="8.8.8.8", port=53, timeout=3):
60+
"""
61+
Check Internet Connections.
62+
:param host: the host that check connection to
63+
:param port: port that check connection with
64+
:param timeout: times that check the connnection
65+
:type host:str
66+
:type port:int
67+
:type timeout:int
68+
:return bool: True if Connection is Stable
69+
>>> internet() # if there is stable internet connection
70+
True
71+
>>> internet() # if there is no stable internet connection
72+
False
73+
"""
74+
try:
75+
socket.setdefaulttimeout(timeout)
76+
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
77+
return True
78+
except Exception as ex:
79+
error_log(str(ex))
80+
return False
81+
5882
if __name__=="__main__":
5983
follower_name="sepandhaghighi"
6084
list_1=follower_list_gen(follower_name)

0 commit comments

Comments
 (0)