dancrichards / ascii-art-splash-screen Goto Github PK
View Code? Open in Web Editor NEWAdd flavour to your terminal screen by showing random ASCII art each time a terminal session opens.
License: GNU General Public License v3.0
Add flavour to your terminal screen by showing random ASCII art each time a terminal session opens.
License: GNU General Public License v3.0
Dear @DanCRichards,
Having recently found your program about ascii generation, I found that it was a great Idea.
I thus took a look into you code (to try and understand how it worked) and was surprised about it's build quality.
I thus re-wrote the code and it supports local and remote image fetching, the next three bullets describes the reaction of to code depending on it's situation:
Sorry no images today
)In order to run the file, it requires execution rigths and/or python3
I hope you like this new version of the script.
Yours sincerely
Henry Letellier
#!/bin/env python3
import random
import os
import requests
default_art = """
#!/bin/env python3
##
## EPITECH PROJECT, 2022
## ASCII-Art-Splash-Screen
## File description:
## ascii_revisited.py
##
# Code written by (c) Henry Letellier (please leave this in the file)
import random
import os
import requests
default_art = """
_________
/ _____/ __________________ ___.__.
\\_____ \\ / _ \\_ __ \\_ __ < | |
/ ( <_> ) | \\/| | \\/\\___ |
/_______ /\\____/|__| |__| / ____|
\\/ \\/
_______
\\ \\ ____
/ | \\ / _ \\
/ | ( <_> )
\\____|__ /\\____/
\\/
.__
|__| _____ _____ ____ ____ ______
| |/ \\\\__ \\ / ___\\_/ __ \\ / ___/
| | Y Y \\/ __ \\_/ /_/ > ___/ \\___ \\
|__|__|_| (____ /\\___ / \\___ >____ >
\\/ \\//_____/ \\/ \\/
__ .___
_/ |_ ____ __| _/____ ___.__.
\\ __\\/ _ \\ / __ |\\__ \\< | |
| | ( <_> ) /_/ | / __ \\\\___ |
|__| \\____/\\____ |(____ / ____|
\\/ \\/\\/
"""
def get_file_content(filename:str, location:str) -> str:
f = open(f"{location}/{filename}", "r", encoding="utf-8")
content = f.read()
f.close()
return content
def display(the_file_content:str) -> None:
print(the_file_content)
def get_file_online(url_start:str, url_end:str, int_max:int) -> str:
content = requests.get(f"{url_start}{str(random.randint(1,int_max))}{url_end}")
if content.status_code == 200:
raw_file_content = content.content
decoded_content = raw_file_content.decode()
if "</html>" not in decoded_content:
return decoded_content
else:
return ""
else:
return ""
usr_location = os.getcwd()
file_url_start = 'https://raw.githubusercontent.com/DanCRichards/ASCII-Art-Splash-Screen/master/art/'
file_url_end = ".txt"
max_nb_files = 9
file_content = get_file_online(file_url_start, file_url_end, max_nb_files)
if file_content == "":
try:
program_location = f"{os.environ['HOME']}/manually_installed_software/ascii_in_terminal/ASCII-Art-Splash-Screen/"
# Change the path of program_location in order to set tge repository containing the folder with the ascii art folder
art_location = "art"
# Change the content of the variable art_location in order to change the name of the folder containing the art files
os.chdir(program_location)
art_files = os.listdir(art_location)
art_file = random.randint(1, len(art_files)-1)
file_name = art_files[art_file]
file_content = get_file_content(file_name, art_location)
os.chdir(usr_location)
except:
file_content = default_art
display(file_content)
PS: I would appreciate it if you leave my credit in the source code
PPS: why not add a file containing the number of available ascii images (avoid's having to hard code it in case you decide to add more images one day, you just have to change the number in the file, no need to roll out a new code for everyone)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.