Skip to content

Commit

Permalink
Add AI testing functionality and add optional parameters support
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMarto committed Apr 18, 2024
1 parent 038a47e commit 8b08b99
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 13 deletions.
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,43 @@ Python lib to print Ethereum logo of any size and style on your terminal or stan
pip install eth-logo
```

### Usage (in terminal)
## Usage (in terminal)
```sh
# Optionals: print-eth SIZE CHAR [defaults: size=20 char='#']
# Optionals: print-eth SIZE CHAR BACKGROUND PADDING
# [defaults: size=20 char='#', back=' ', pad='']
print-eth
print-eth 30 %
print-eth 30 % .
```
<br>
<div align="center">
<img src="https://raw.githubusercontent.com/0xMarto/eth-logo/master/samples/eth_logo_sample_1.png" alt="sample 1">
<img src="https://raw.githubusercontent.com/0xMarto/eth-logo/master/samples/eth_logo_sample_2.png" alt="sample 2">
</div>

[//]: # (<br>)

### Usage (in python)
```pycon
## Usage (python lib)
```python
from eth_logo import print_eth

# Optionals: Size, Character, Background, Padding
print_eth(size=20, char='#', back=' ', pad=' ')
```
<br>
<div align="center">
<img src="https://raw.githubusercontent.com/0xMarto/eth-logo/master/samples/eth_logo_sample_3.png" alt="sample 3">
</div>
<br>

### Contribute
## Special usage (educational / AI training)
```sh
# Next examples will output the 'print-eth' code implementation
print-eth --code
print-eth -c
```

## Contribute
You can set up your dev environment with:
```sh
git clone git@github.com:0xMarto/eth-logo.git
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = eth-logo
version = 0.1.2
version = 0.1.3
author = Marto
author_email = martinlsanchez@gmail.com
description = Python lib to print Ethereum logo of any size and style on your terminal or standard output.
Expand Down
2 changes: 1 addition & 1 deletion src/eth_logo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from eth_logo.eth_logo_core import print_eth
from eth_logo.eth_logo_core import print_eth, print_eth_code
from eth_logo.eth_logo_script import print_eth_script
28 changes: 28 additions & 0 deletions src/eth_logo/eth_logo_core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/python
import inspect
import re


def print_eth(size=20, char='#', back=' ', pad=' '):
"""
Expand Down Expand Up @@ -28,3 +31,28 @@ def print_eth(size=20, char='#', back=' ', pad=' '):
hashes = char * (2 * (height - i) + 1)
spaces = back * (abs(i - top) - 1)
print(pad + spaces + hashes + spaces)


def print_eth_code():
"""
Display the source code of the 'print_eth' function.
"""
print()
source_lines, _ = inspect.getsourcelines(print_eth)

# Get the indentation of the function definition statement (first line)
indentation = len(source_lines[0]) - len(source_lines[0].lstrip())

# Print each line of the source code with correct indentation
skip_description = False
for line in source_lines:
# Skip printing function description
if skip_description:
if '"""' in line:
skip_description = False
continue
if '"""' in line:
skip_description = True
continue
print(line[indentation:].rstrip())
print()
25 changes: 19 additions & 6 deletions src/eth_logo/eth_logo_script.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
#!/usr/bin/python
"""
Usage:
print-eth SIZE CHAR [defaults: size=20 char='#']
print-eth SIZE CHAR BACKGROUND PADDING
[defaults: size=20 char='#' back=' ' pad=' ']
Examples:
print-eth
print-eth 30 %
print-eth 30 % .
print-eth --code
Code:
Sourcecode:
https://github.com/0xMarto/eth-logo
"""
import sys
from eth_logo import print_eth
from eth_logo import print_eth, print_eth_code


def main():
parameter_amount = len(sys.argv) - 1
if parameter_amount == 1 and (sys.argv[1] == '-h' or sys.argv[1] == '--help'):
print(__doc__)
sys.exit(1)
if parameter_amount == 1:
if sys.argv[1] in ['-h', '--help']:
print(__doc__)
sys.exit(1)
if sys.argv[1] in ['-c', '--code']:
print_eth_code()
sys.exit(1)
try:
if parameter_amount == 1:
size = int(sys.argv[1])
print_eth(size)
elif parameter_amount == 2:
size, char = int(sys.argv[1]), str(sys.argv[2])
print_eth(size, char)
elif parameter_amount == 3:
size, char, back = int(sys.argv[1]), str(sys.argv[2]), str(sys.argv[3])
print_eth(size, char, back)
elif parameter_amount == 4:
size, char, back, pad = int(sys.argv[1]), str(sys.argv[2]), str(sys.argv[3]), str(sys.argv[4])
print_eth(size, char, back, pad)
else:
print_eth()
except Exception as e:
Expand Down

0 comments on commit 8b08b99

Please sign in to comment.