mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-27 14:01:09 +00:00
Added PX to REM, REM to Px as command line tools (#82)
Co-authored-by: Atthaphon Urairat <aurairat@inetasia.com> Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com>
This commit is contained in:
parent
d7ca9f5ab2
commit
587a083db6
9
PX-to-REM/README.md
Normal file
9
PX-to-REM/README.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# PX-to-REM Script
|
||||
|
||||
This script can convert **PX to REM** and **REM to PX**
|
||||
|
||||
## Usage call python script then select your interest **PX to REM** or **REM to PX** to convert
|
||||
|
||||
``` bash
|
||||
$ python px_to_rem.py
|
||||
```
|
11
PX-to-REM/converter.py
Normal file
11
PX-to-REM/converter.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
class Converter:
|
||||
base_px = 16
|
||||
|
||||
def __init__(self):
|
||||
self.data = []
|
||||
|
||||
def px_to_rem(self, px):
|
||||
return float(px) / self.base_px
|
||||
|
||||
def rem_to_px(self, rem):
|
||||
return float(rem) * self.base_px
|
69
PX-to-REM/px_to_rem.py
Normal file
69
PX-to-REM/px_to_rem.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
import sys
|
||||
from converter import Converter
|
||||
|
||||
def get_input(msg = ''):
|
||||
if (sys.version_info > (3, 0)):
|
||||
return input(msg)
|
||||
else:
|
||||
return raw_input(msg)
|
||||
|
||||
def is_int_or_float(value):
|
||||
return value.isdigit()
|
||||
|
||||
def process_check(value, callback):
|
||||
if value == 'Q' or value == 'q':
|
||||
user_selected(value)
|
||||
elif value == 'C' or value == 'c':
|
||||
if (callback.__name__ == 'process_px_to_rem'):
|
||||
process_rem_to_px()
|
||||
return
|
||||
else:
|
||||
process_px_to_rem()
|
||||
return
|
||||
elif is_int_or_float(value) == False:
|
||||
print("Warning:: Allowed number only! Or if you need to qute plesae enter Q.\n")
|
||||
callback()
|
||||
|
||||
def process_px_to_rem():
|
||||
px = get_input("[PX to REM] Enter a number of px that need to convert to rem. Enter C to Change to [REM to PX] or Q to quit!\n")
|
||||
|
||||
process_check(px, process_px_to_rem)
|
||||
|
||||
rem = Converter().px_to_rem(px)
|
||||
print("%spx == %srem" % (px, rem))
|
||||
process_px_to_rem()
|
||||
|
||||
def process_rem_to_px():
|
||||
rem = get_input("[REM to PX] Enter a number of rem that need to convert to px. Enter C to Change to [PX to REM] or Q to quit!\n")
|
||||
|
||||
process_check(rem, process_rem_to_px)
|
||||
|
||||
px = Converter().rem_to_px(rem)
|
||||
print("%srem == %spx" % (rem, px))
|
||||
process_rem_to_px()
|
||||
|
||||
def user_selected(user_input):
|
||||
if user_input == 'A' or user_input == 'a': # PX to REM
|
||||
process_px_to_rem()
|
||||
elif user_input == 'B' or user_input == 'b': # REM to PX
|
||||
process_rem_to_px()
|
||||
elif user_input == 'Q' or user_input == 'q':
|
||||
print("Nice to meet you. See you next time!")
|
||||
exit()
|
||||
else:
|
||||
print("""
|
||||
Please Selected A or B to continue, Q to quit...
|
||||
""")
|
||||
user_input = get_input()
|
||||
user_selected(user_input)
|
||||
|
||||
|
||||
# Start
|
||||
user_input = get_input("""
|
||||
Please select your converter.
|
||||
|
||||
A. PX to REM
|
||||
B. REM to PX
|
||||
""");
|
||||
|
||||
user_selected(user_input)
|
|
@ -70,6 +70,7 @@ So far, the following projects have been integrated to this repo:
|
|||
|[CLI Calculator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/cli_calculator)|[Willian GL](https://github.com/williangl) |
|
||||
|[Find PhoneNumber in String](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Find-PhoneNumber-in-String)|[Austin Zuniga](https://github.com/AustinZuniga)|
|
||||
|[IMDB TV Series Info Extractor](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/imdb_episode_ratings)|[Yash Raj Sarrof](https://github.com/yashYRS) |
|
||||
|[PX to REM](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/PX-to-REM)|[Atthaphon Urairat](https://github.com/uatthaphon) |
|
||||
|[Yoda-speak Translator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/speak_like_yoda)|[sonniki](https://github.com/sonniki) |
|
||||
|[Wikipedia-Search](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Wikipedia-Search)|[Nissaar](https://github.com/Nissaar) |
|
||||
|[Instagram Video Downloader](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/insta_video_downloader)|[Shobhit Bhosure](https://github.com/shobhit99) |
|
||||
|
|
Loading…
Reference in New Issue
Block a user