Skip to content

Commit c75f007

Browse files
Update main.py
1 parent 5acc116 commit c75f007

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

main.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
PYFETCH_VERSION = "1.1.2" # Changing the version in this line is highly not recommended.
3+
PYFETCH_VERSION = "1.1.3" # Changing the version in this line is highly not recommended.
44
import os
55

66
# Load ~/.config/pyfetch/pyfetch.conf
@@ -32,6 +32,7 @@ def load_conf(path):
3232
import subprocess
3333
import argparse
3434
import time
35+
import requests
3536
import random
3637
pluginloader_path = os.path.expanduser("~/.config/pyfetch")
3738
sys.path.append(pluginloader_path)
@@ -72,6 +73,14 @@ def get_shell_version():
7273
except Exception:
7374
return f"{shell_name} (version unknown)"
7475

76+
# Load Public IP Address
77+
def get_public_ip():
78+
try:
79+
ip = requests.get("https://api.ipify.org").text
80+
return ip
81+
except requests.RequestException:
82+
return "Unavailable"
83+
7584
# Load plugins
7685
plugin_dir = os.path.expanduser("~/.config/pyfetch/plugins")
7786
plugins = load_plugins(plugin_dir)
@@ -181,7 +190,11 @@ def get_desktop_environment():
181190
"Did you know PyFetch has the MIT License?",
182191
"The PyFetch github is https://github.com/linuxaddict124/pyfetch",
183192
"Python is great for AI!",
184-
"I wonder if Python websites exist."
193+
"I wonder if Python websites exist.",
194+
"Did you know that the official PyFetch website is pyfetch.github.io?",
195+
"Did you know the most popular distros are based on Ubuntu?",
196+
"Did you know both MacOS and Ubuntu are based on Unix? I wonder why XNU stands for 'X is Not Unix' then...",
197+
"Java is more complicated than Python. Don't believe it? Try to print Hello World in Java."
185198
]
186199
random_fact = random.choice(facts)
187200

@@ -210,6 +223,8 @@ def pyfetchbase():
210223
print("Fun Fact:", random_fact)
211224
if cfg.get('show_pyfversion', 'true') == 'true':
212225
print(f"PyFetch Version:", PYFETCH_VERSION)
226+
if cfg.get('show_ip', 'true') == 'true':
227+
print(f"Public IP: {get_public_ip()}")
213228
if cfg.get('show_shell_version', 'true') == 'true':
214229
print("Shell:", get_shell_version())
215230
if cfg.get('show_battery', 'true') == 'true':
@@ -236,6 +251,7 @@ def pyfetchbasenonconfig():
236251
print("Packages: Unknown")
237252
print("Fun Fact:", random_fact)
238253
print(f"PyFetch Version:", PYFETCH_VERSION)
254+
print(f"Public IP: {get_public_ip()}")
239255
print("Shell:", get_shell_version())
240256
print("Battery:", get_battery_percentage())
241257
print(f"CPU: {os.uname().machine}")
@@ -266,6 +282,8 @@ def nopluginsbase():
266282
print("Fun Fact:", random_fact)
267283
if cfg.get('show_pyfversion', 'true') == 'true':
268284
print(f"PyFetch Version:", PYFETCH_VERSION)
285+
if cfg.get('show_ip', 'true') == 'true':
286+
print(f"Public IP: {get_public_ip()}")
269287
if cfg.get('show_shell_version', 'true') == 'true':
270288
print("Shell:", get_shell_version())
271289
if cfg.get('show_battery', 'true') == 'true':
@@ -287,6 +305,8 @@ def nopluginsbase():
287305
parser.add_argument("--fun-fact", action="store_true", help="Show some fun facts")
288306
parser.add_argument("--edit-config", action="store_true", help="A easier way to edit pyfetch.conf")
289307
parser.add_argument("--desktop", action="store_true", help="Show your desktop environment")
308+
parser.add_argument("--public-ip", action="store_true", help="Show your Public IP")
309+
parser.add_argument("--kernel", action="store_true", help="Show your Kernel Version")
290310
args = parser.parse_args()
291311

292312
if args.minimal:
@@ -338,6 +358,14 @@ def nopluginsbase():
338358
if args.desktop:
339359
print(f"Desktop Environment: {de}")
340360
exit()
361+
362+
if args.public_ip:
363+
print(f"Public IP: {get_public_ip()}")
364+
exit()
365+
366+
if args.kernel:
367+
print(f"Kernel: {platform.system()} {platform.release()}")
368+
exit()
341369

342370
# If no flags are running
343371
pyfetchbase()

0 commit comments

Comments
 (0)