diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e984e23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +*.xml diff --git a/submissions/k17pine/data_structures/README.md b/submissions/k17pine/data_structures/README.md new file mode 100644 index 0000000..8a20ac5 --- /dev/null +++ b/submissions/k17pine/data_structures/README.md @@ -0,0 +1,21 @@ +# Stack and linked list + +Here is client and server for exchanging information via web. + +## Getting Started + +Some commands, that you could use on the client side: +push arg - push something into stack +pop - pop last arg from stack +insert arg arg2* arg3* - insert element to the linked list. arg2 could be 'before' or 'after', and arg3 show point from this insertion +remove arg - remove one argument from list +show all - show all linked list +exit - exit from client +* - optional arguments + +## Acknowledgments + +* Hat tip to anyone whose code was used +* Inspiration +* etc + diff --git a/submissions/k17pine/data_structures/client.py b/submissions/k17pine/data_structures/client.py new file mode 100644 index 0000000..442b744 --- /dev/null +++ b/submissions/k17pine/data_structures/client.py @@ -0,0 +1,15 @@ +import socket + +HOST = '127.0.0.1' # The server's hostname or IP address +PORT = 65432 # The port used by the server +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +s.connect((HOST, PORT)) +while True: + #s.sendall(b'Hello, world') + mess = (input()) + if mess.split()[0] == 'exit': + exit() + s.sendall(bytes((mess), encoding='utf-8')) + data = s.recv(1023) + print('Received:', (data.decode("utf-8"))) + diff --git a/submissions/k17pine/data_structures/server.py b/submissions/k17pine/data_structures/server.py new file mode 100644 index 0000000..b0f2003 --- /dev/null +++ b/submissions/k17pine/data_structures/server.py @@ -0,0 +1,86 @@ +import socket +import time + + +def stack_push(arg): + stack.append(arg) + return f'{arg} pushed' + + +def stack_pop(): + if len(stack) == 0: + return 'Stack is NULL' + else: + return stack.pop() + + +def list_insert(arg): + try: + if arg[2] == 'before': + pos = arr.index(arg[3]) + arr.insert(pos, arg[1]) + return f'{arg[1]} inserted before {arg[3]}' + if arg[2] == 'after': + pos = arr.index(arg[3]) + arr.insert(pos+1, arg[1]) + return f'{arg[1]} inserted after {arg[3]}' + except IndexError: + arr.insert(len(arr), arg[1]) + return f'{arg[1]} inserted' + except ValueError: + return f'There is no {arg[3]} in the list' + + +def list_remove(arg): + try: + arr.remove(arg) + return f'{arg} removed' + except ValueError: + return f'How dare you? {arg} not in list' + + +def list_show(): + if len(arr) == 0: + return 'List is empty' + else: + ans = '' + for i in arr: + if ans == '': + ans = i + else: + ans = ans + ' - ' + i + return ans + + +def com(txt): + x = txt.split() + try: + if x[0] == 'push': + ans = stack_push(x[1]) + if x[0] == 'pop': + ans = stack_pop() + if x[0] == 'insert': + ans = list_insert(x) + if x[0] == 'remove': + ans = list_remove(x[1]) + if x[0] == 'show' and x[1] == 'all': + ans = list_show() + return ans + except IndexError: + return f'Look like you forgot some arguments, lol' + + +HOST = '127.0.0.1' # Standard loopback interface address (localhost) +PORT = 65432 # Port to listen on (non-privileged ports are > 1023) +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +stack = [] +arr = [] + +s.bind((HOST, PORT)) +s.listen(2) # 2 connections +conn, addr = s.accept() # conn is client socket +print('Connected by', addr) +while True: + data = conn.recv(1023) + new_data = com(data.decode("utf-8")) + conn.sendall(bytes(new_data, encoding='utf-8')) diff --git a/submissions/k17pine/wheater_app/.idea/.gitignore b/submissions/k17pine/wheater_app/.idea/.gitignore new file mode 100644 index 0000000..0e40fe8 --- /dev/null +++ b/submissions/k17pine/wheater_app/.idea/.gitignore @@ -0,0 +1,3 @@ + +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/submissions/k17pine/wheater_app/.idea/wheater_app.iml b/submissions/k17pine/wheater_app/.idea/wheater_app.iml new file mode 100644 index 0000000..d7db3b1 --- /dev/null +++ b/submissions/k17pine/wheater_app/.idea/wheater_app.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/submissions/k17pine/wheater_app/Locations.txt b/submissions/k17pine/wheater_app/Locations.txt new file mode 100644 index 0000000..51baf93 --- /dev/null +++ b/submissions/k17pine/wheater_app/Locations.txt @@ -0,0 +1,62 @@ +Kyiv +Krim +Karpati +Lonhon +Kherson +Kherson +Mexiko +Brasilia +Brasilia +Brasilia +Bon +Bon +London +London +London +Kyiv +Kyiv +London +Kyiv +London +lat=12&lon=134 +Kyiv +Kyiv +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=1&lon=66 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +London +London +London +London +London +London +London +London +London +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 +lat=12&lon=134 diff --git a/submissions/k17pine/wheater_app/my-weather-app.py b/submissions/k17pine/wheater_app/my-weather-app.py new file mode 100644 index 0000000..b0d4e15 --- /dev/null +++ b/submissions/k17pine/wheater_app/my-weather-app.py @@ -0,0 +1,104 @@ +import urllib.request +import argparse +from collections import Counter + +apikey = '2ae04d95d78eb539f7b8cce05a16f9e5' + + +def top(): + line_list = [this_line.rstrip('\n') for this_line in open('Locations.txt')] + l_sorted = Counter(line_list).most_common() + try: + print('Most popular queries:') + print(l_sorted[0][0]) + print(l_sorted[1][0]) + print(l_sorted[2][0]) + print('What query do you like?') + by_location(input()) + except IndexError: + pass + exit() + + +def by_location(city_name): + if city_name[0:4] == 'lat=': + q = 'http://api.openweathermap.org/data/2.5/forecast?' + city_name + '&APPID=' + apikey + else: + q = 'http://api.openweathermap.org/data/2.5/forecast?q=' + city_name + '&APPID=' + apikey + try: + fp = urllib.request.urlopen(q) + mybytes = fp.read() + mystr = mybytes.decode('utf8') + fp.close() + except urllib.error.HTTPError: + print('Wrong city or cords!!!') + exit() + if mystr == '{"cod": 500,"message": "Internal server error"}': + print('Wrong city or cords!') + exit() + else: + decode(mystr) + f = open('Locations.txt', 'a+') + f.write(city_name + '\n') + f.close() + exit() + + +def last_city(number): + try: + with open('Locations.txt', 'r') as f: + lines = f.read().splitlines() + line = lines[-int(number):-1] + line.append(lines[-1]) + return line + except IndexError: + print('Please enter the location') + + +def decode(page): + new_data = page.split('"') + pa = [i for i, x in enumerate(new_data) if x == 'temp'] + if args.range == 'day': + print("Temp = " + translate((new_data[pa[8] + 1]).strip(':,'))) + else: + print("Temp = " + translate((new_data[pa[39] + 1]).strip(':,'))) + + +def translate(temperature): + if not args.degrees: + new_temperature = float(temperature) - 273.15 + else: + new_temperature = float(temperature) * 9 / 5 - 459.67 + return str(format(new_temperature, '.2f')) + + +parser = argparse.ArgumentParser(description='Weather app #37462189') +subparsers = parser.add_subparsers() +parser.add_argument('--l', '-location', dest='location', default=None, type=str, help='Location by city') +parser.add_argument('--r', '-range', dest='range', choices=('day', 'week'), default='day', + type=str, help='Range (week/day)') +parser.add_argument('--c', '-cords', nargs=2, dest='cords', type=str, + help='Location by coordinates, 2 floats, lon&lat') +parser.add_argument('--d', '-celsius', action='store_false', default=False, dest='degrees', + help='Show Celsius degrees (default)') # false +parser.add_argument('--f', '-fahrenheit', action='store_true', default=False, dest='degrees', + help='Show Fahrenheit degrees') +parser.add_argument('--q', '-resent', dest='resent', + help='Show N resent towns, or 0 for all locations') +parser_top = subparsers.add_parser('top', help='list of 3 favorite cities') +parser_top.set_defaults(func=top) +args = parser.parse_args() +try: + args.func() +except AttributeError: + pass +if args.resent is not None: + print(last_city(args.resent)) +if args.cords is not None: + by_location('lat=' + args.cords[0] + '&lon=' + args.cords[1]) +if args.location is not None: + by_location(args.location) +if (args.cords is None) and (args.location is None) and (args.resent is None): + last = (str(last_city(1)[0])) + print(last) + by_location(last)