Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions in-class-project/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ def make_api_call(currency):

else:
result_obj = res.json()
return result_obj

return result_obj
2 changes: 1 addition & 1 deletion in-class-project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
curr = get_currency()
result_dct = make_api_call(currency=curr)
clean_dct = clean_result(dct=result_dct)
save_file(obj=clean_dct)
save_file(obj=clean_result)
473 changes: 473 additions & 0 deletions random-uc-app/Scripts/Activate.ps1

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions random-uc-app/Scripts/activate
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly

deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
PATH="${_OLD_VIRTUAL_PATH:-}"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi

if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
PS1="${_OLD_VIRTUAL_PS1:-}"
export PS1
unset _OLD_VIRTUAL_PS1
fi

unset VIRTUAL_ENV
unset VIRTUAL_ENV_PROMPT
if [ ! "${1:-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}

# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV="D:\Python\Class7-Python-Module-Week3\random-uc-app"
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/Scripts:$PATH"
export PATH

# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
unset PYTHONHOME
fi

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1:-}"
PS1="(random-uc-app) ${PS1:-}"
export PS1
VIRTUAL_ENV_PROMPT="(random-uc-app) "
export VIRTUAL_ENV_PROMPT
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi
34 changes: 34 additions & 0 deletions random-uc-app/Scripts/activate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@echo off

rem This file is UTF-8 encoded, so we need to update the current code page while executing it
for /f "tokens=2 delims=:." %%a in ('"%SystemRoot%\System32\chcp.com"') do (
set _OLD_CODEPAGE=%%a
)
if defined _OLD_CODEPAGE (
"%SystemRoot%\System32\chcp.com" 65001 > nul
)

set VIRTUAL_ENV=D:\Python\Class7-Python-Module-Week3\random-uc-app

if not defined PROMPT set PROMPT=$P$G

if defined _OLD_VIRTUAL_PROMPT set PROMPT=%_OLD_VIRTUAL_PROMPT%
if defined _OLD_VIRTUAL_PYTHONHOME set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%

set _OLD_VIRTUAL_PROMPT=%PROMPT%
set PROMPT=(random-uc-app) %PROMPT%

if defined PYTHONHOME set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
set PYTHONHOME=

if defined _OLD_VIRTUAL_PATH set PATH=%_OLD_VIRTUAL_PATH%
if not defined _OLD_VIRTUAL_PATH set _OLD_VIRTUAL_PATH=%PATH%

set PATH=%VIRTUAL_ENV%\Scripts;%PATH%
set VIRTUAL_ENV_PROMPT=(random-uc-app)

:END
if defined _OLD_CODEPAGE (
"%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul
set _OLD_CODEPAGE=
)
22 changes: 22 additions & 0 deletions random-uc-app/Scripts/deactivate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@echo off

if defined _OLD_VIRTUAL_PROMPT (
set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
)
set _OLD_VIRTUAL_PROMPT=

if defined _OLD_VIRTUAL_PYTHONHOME (
set "PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%"
set _OLD_VIRTUAL_PYTHONHOME=
)

if defined _OLD_VIRTUAL_PATH (
set "PATH=%_OLD_VIRTUAL_PATH%"
)

set _OLD_VIRTUAL_PATH=

set VIRTUAL_ENV=
set VIRTUAL_ENV_PROMPT=

:END
Binary file added random-uc-app/Scripts/normalizer.exe
Binary file not shown.
Binary file added random-uc-app/Scripts/pip.exe
Binary file not shown.
Binary file added random-uc-app/Scripts/pip3.10.exe
Binary file not shown.
Binary file added random-uc-app/Scripts/pip3.exe
Binary file not shown.
Binary file added random-uc-app/Scripts/python.exe
Binary file not shown.
Binary file added random-uc-app/Scripts/python_d.exe
Binary file not shown.
Binary file added random-uc-app/Scripts/pythonw.exe
Binary file not shown.
Binary file added random-uc-app/Scripts/pythonw_d.exe
Binary file not shown.
18 changes: 18 additions & 0 deletions random-uc-app/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import requests
import sys

def api_call_dic(user):

res = requests.get('http://jsonplaceholder.typicode.com/users')
result_obj = res.json()
try:
(res.status_code) # code 200

if res.status_code >= 400:
raise requests.exceptions.HTTPError(" Sorry, the database is not available! ʕ •`ᴥ•´ʔ ")

except requests.exceptions.HTTPError as exc:
print(exc)
sys.exit()

return result_obj
16 changes: 16 additions & 0 deletions random-uc-app/cleanup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from api import api_call_dic
import requests

def clean_result(dic):

res = requests.get('http://jsonplaceholder.typicode.com/users')
result_obj = res.json()
new_dct = {
"id":result_obj[dic]['id'],
"name":result_obj[dic]['name'],
"username":result_obj[dic]['username'],
"email":result_obj[dic]['email'],
}
print(new_dct)

return new_dct
11 changes: 11 additions & 0 deletions random-uc-app/get_random_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def get_rdm_user():
while True:
print("\n Welcome to Random User Creator App! ")
print ('\n This app generates random users from a database ʕ•ᴥ•ʔ \n')
try:
user = int(input(" Please type how many random users you want to know: "))
break

except:
print("\n (;¬_¬) Wrong choice... (;¬_¬) ")
return user
8 changes: 8 additions & 0 deletions random-uc-app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from api import api_call_dic
from save_to_file import save_file
from utils import start


ram_user = start(0)
result_dct = api_call_dic(user= ram_user)
save_file(obj = ram_user)
3 changes: 3 additions & 0 deletions random-uc-app/pyvenv.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
home = C:\Program Files\Python310
include-system-site-packages = false
version = 3.10.6
6 changes: 6 additions & 0 deletions random-uc-app/ramdom_user_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": 8,
"name": "Nicholas Runolfsdottir V",
"username": "Maxime_Nienow",
"email": "Sherwood@rosamond.me"
}
Binary file added random-uc-app/requirements.txt
Binary file not shown.
7 changes: 7 additions & 0 deletions random-uc-app/save_to_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import json


def save_file(obj):

with open('random-uc-app/ramdom_user_.json', "w") as f:
json.dump(obj, f, indent=4)
15 changes: 15 additions & 0 deletions random-uc-app/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from cleanup import clean_result
from get_random_user import get_rdm_user
import random


def rdm_num (rdm):
rdm = random.choice(range(1,10))
return rdm

def start (spu):
spu = get_rdm_user()

for vr in range(spu):
dit = (clean_result((rdm_num(0))))
return dit