├── data ├── run.sh ├── README.md └── main.py /data: -------------------------------------------------------------------------------- 1 | . 2 | --------------------------------------------- 3 | | c1 > c2 | 4 | --------------------------------------------- 5 | . 6 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | python3 -m pip install requests 2 | 3 | rm -rf $HOME/logtime_count 4 | mkdir $HOME/.logtime 5 | 6 | cp main.py $HOME/.logtime/ 7 | 8 | echo 'alias logtime="python3 ~/.logtime/main.py"' >> $HOME/.zshrc 9 | echo "**Installed uccessfully**" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Logtime 2 | 3 | ## Only for 1337-med students 4 | 5 | simples script to know your logtime just by typing 'logitme' in terminal 6 | 7 | NB : the app can only be used only in your mac (nor user input nedeed) 8 | 9 | To start clone this repo 10 | 11 | ## Installation 12 | 13 | Clone repo (you can delete it after running script successfully) 14 | 15 | ```bash 16 | git clone git@github.com:eyubech/logtime_counter.git 17 | ``` 18 | 19 | Go to logtime_counter folder 20 | 21 | And type this command 22 | 23 | ```bash 24 | ./run 25 | ``` 26 | Now open new terminal and type logtime 27 | 28 | ```bash 29 | logtime 30 | ``` 31 | ## Version 1 32 | Screen Shot 2023-01-04 at 12 10 28 PM 33 | 34 | ## Version 2 35 | Screen Shot 2023-01-04 at 1 57 22 PM 36 | 37 | 38 | ## Version 3 39 | Screen Shot 2023-12-15 at 3 10 46 PM 40 | 41 | Data source : http://logtime-med.1337.ma/ 42 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from datetime import date, timedelta 2 | from datetime import datetime 3 | import requests 4 | import json 5 | import sys 6 | import os 7 | 8 | 9 | today = date.today() 10 | url = "https://logtime-med.1337.ma/api/get_log" 11 | if len(sys.argv) < 2: 12 | user = os.popen("users").read().strip() 13 | else : 14 | user = sys.argv[1] 15 | 16 | first_day_of_current_month = today.replace(day=1) 17 | last_day_of_last_month = first_day_of_current_month - timedelta(days=1) 18 | start_date = last_day_of_last_month.replace(day=29) 19 | end_date = today.replace(day=28) 20 | 21 | 22 | payload = f'{{"login": "{user}", "startDate": "{today}T00:00:00.000Z", "endDate": "{today}T23:59:59.999Z"}}' 23 | payload2 = f'{{"login": "{user}", "startDate": "{start_date}T00:00:00.000Z", "endDate": "{end_date}T23:59:59.999Z"}}' 24 | 25 | 26 | headers = { 27 | 'Content-Type': 'application/json' 28 | } 29 | 30 | response = requests.request("POST", url, headers=headers, data = payload) 31 | response2 = requests.request("POST", url, headers=headers, data = payload2) 32 | try: 33 | today_hours = int((json.loads(response.text)['hydra:member'])[0]['totalHours']) 34 | except: 35 | today_hours = 0 36 | total_hours = int((json.loads(response2.text)['hydra:member'])[0]['totalHours']) 37 | now = datetime.now() 38 | dt_string = now.strftime("%d") 39 | 40 | data = os.popen("who").read().strip() 41 | components = data.split() 42 | month = components[2] 43 | day = int(components[3]) 44 | time_str = components[4] 45 | current_datetime = datetime.now() 46 | parsed_datetime = datetime(current_datetime.year, datetime.strptime(month, '%b').month, day) 47 | parsed_time = datetime.strptime(time_str, '%H:%M') 48 | parsed_datetime += timedelta(hours=parsed_time.hour, minutes=parsed_time.minute) 49 | time_difference = current_datetime - parsed_datetime 50 | hours_difference = time_difference.total_seconds() / 3600 51 | 52 | logtime_header = '\033[95m' + ''' 53 | .__ __ .__ 54 | | | ____ _____/ |_|__| _____ ____ 55 | | | / _ \\ / ___\\ __\\ |/ \\_/ __ \\ 56 | | |_( <_> ) /_/ > | | | Y Y \\ ___/ 57 | |____/\\____/\\___ /|__| |__|__|_| /\\___ > 58 | /_____/ \\/ \\/ 59 | ''' + '\033[0m' 60 | 61 | print(logtime_header) 62 | 63 | green_color = '\033[92m' 64 | yellow_color = '\033[93m' 65 | red_color = '\033[91m' 66 | reset_color = '\033[0m' 67 | brown_color = '\033[33m' 68 | orange_color = '\033[38;5;208m' 69 | 70 | 71 | print(f"{green_color}\tYour total hours for today : {today_hours}\t\tafter logout ~ [{int(hours_difference + today_hours)}]{reset_color}") 72 | print(f"{yellow_color}\tYour total hours for this month : {total_hours}\t\tafter logout ~ [{int(hours_difference + total_hours)}]{reset_color}") 73 | 74 | 75 | 76 | if (28 - int(dt_string) > 11) : 77 | color = brown_color 78 | if (28 - int(dt_string) >= 10): 79 | color = orange_color 80 | else: 81 | color = red_color 82 | 83 | dt_int = int(dt_string) 84 | if (dt_int >= 28): 85 | dt_int = 27 86 | 87 | est = (120 - total_hours) / (28 - dt_int) 88 | 89 | if (28 - int(dt_string) > 0 and est > 0) : 90 | print(f"{color}\tLeft days : {28 - int(dt_string)}\t\tEstimated[{est:.1f}h/d] {reset_color}") 91 | else : 92 | print(f"{color}\tEligible for a scholarship [if you're not blacklisted :)]{reset_color}") 93 | 94 | try : 95 | print(f"") 96 | ads_content = os.popen("curl -s https://raw.githubusercontent.com/eyubech/logtime_counter/master/data").read().strip() 97 | print(f"\033[95m\tAds section [{ads_content}]{reset_color}") 98 | print(f"") 99 | print(f"\t \033[95m< To put ur ads here please contact [aech-che] >{reset_color}") 100 | except: 101 | print(f"\033[95m\tAds section [Not available]{reset_color}") --------------------------------------------------------------------------------