Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import time
- import requests
- SERVER_IP ='52.89.157.137'
- SERVER_PORT = 77
- date = time.strftime("%d/%m/%Y")
- def connect_and_send(msg):
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- server_address = (SERVER_IP, SERVER_PORT)
- sock.connect(server_address)
- sock.sendall(msg.encode())
- server_msg = sock.recv(1024)
- server_msg = server_msg.decode()
- #print(server_msg)
- sock.sendall(msg.encode())
- server_msg = sock.recv(1024)
- server_msg = server_msg.decode()
- sock.close()
- return server_msg
- def find_checksum(city, date):
- """
- this function find a checksum
- param city: a city that the user chose, string
- param date: a date that the user chose, string
- return: the checksum, string
- """
- checksum_before = 0
- checksum_after = 0
- for num in date:
- if num.isdigit():
- checksum_after +=int(num)
- for word in city_choice:
- if word.isalpha():
- checksum_before += ord(word.lower())-96
- return str(checksum_before) + '.' + str(checksum_after)
- file_name = "C:\Users\user\Downloads\capitals20.txt"
- with open(file_name, "r") as f:
- file = f.read()
- print(file)
- names = []
- text = file.split("/n")
- for i in text:
- names.append(i.split(",")[2])
- msg = "100:REQUEST:city="+names[i]+"&date="+date+"&checksum="+find_checksum(names[i], date)
- server_msg = connect_and_send(msg)
- server_msg.split(", ")
- dict[server_msg[7]] = names[i]
- sorted(dict)
- print(dict[value], dict[key] + "degrees")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement