DeletedUser
Guest
This part contains:
- imports
- variable declaration
- definitions for reading world data and storing these in files in a /DATA subdir of the dir you have stored this python file (you have to make this directory yourself)
- imports
- variable declaration
- definitions for reading world data and storing these in files in a /DATA subdir of the dir you have stored this python file (you have to make this directory yourself)
Code:
import pygame, sys, time, datetime, os
import urllib.request
from pygame.locals import *
from tkinter import *
from tkinter.colorchooser import askcolor
from time import *
from datetime import datetime
## The following variables are common global variables
global debug; debug = 0
global BLACK; BLACK = (0, 0, 0)
global WHITE; WHITE = (255, 255, 255)
global RED; RED = (255, 0, 0)
global GREEN; GREEN = (0, 255, 0)
global BLUE; BLUE = (0, 0, 255)
global GREY; GREY = (100, 100, 100)
global pics_hor; pics_hor = 1000
global pics_ver; pics_ver = 1000
## The following are the default URLs of the world data
url_players = 'http://en4.grepolis.com/data/players.txt'
url_conquers= 'http://en4.grepolis.com/data/conquers.txt'
url_alliances='http://en4.grepolis.com/data/alliances.txt'
url_towns ='http://en4.grepolis.com/data/towns.txt'
## The following variables are the offsets for towns on each island type
island_1dx = [24,17,10,5,5,7,12,18,25,29,35,42,47,52,57,54,51,45,49,47]
island_1dy = [17,20,24,27,31,36,36,37,42,44,41,41,40,37,33,29,22,24,28,31]
island_7dx = [19,17,16,16,20,24,31,35,45,40,42,45,45,40,40,35,29,24,20,17]
island_7dy = [27,25,21,18,16,18,20,22,23,25,29,32,36,38,43,43,41,43,41,39]
## ----------------------------------------------------------
##
## The following routines read the world data from the internet
## using the URL provided as an argument
## The data is stored in data files in a \DATA subdirectory
## The "r"in the open statement makes the string a raw string
## to avoid problems with the backslask escape chatacter
##
## ----------------------------------------------------------
def read_players(url):
req = urllib.request.Request(url)
response = urllib.request.urlopen(req)
f = open(r'data\players.txt', 'w')
for line in response:
player = str(line)
f.write(player[2:len(player)-3])
f.write('\n')
f.close()
def read_conquers(url):
req = urllib.request.Request(url)
response = urllib.request.urlopen(req)
f = open(r'data\conquers.txt', 'w')
for line in response:
conquer = str(line)
f.write(conquer[2:len(conquer)-3])
f.write('\n')
f.close()
def read_alliances(url):
req = urllib.request.Request(url)
response = urllib.request.urlopen(req)
f = open(r'data\alliances.txt', 'w')
for line in response:
alliance = str(line)
f.write(alliance[2:len(alliance)-3])
f.write('\n')
f.close()
def read_towns(url):
req = urllib.request.Request(url)
response = urllib.request.urlopen(req)
f = open(r'data\towns.txt', 'w')
for line in response:
town = str(line)
f.write(town[2:len(town)-3])
f.write('\n')
f.close()
def read_islands(url):
req = urllib.request.Request(url)
response = urllib.request.urlopen(req)
f = open(r'data\islands.txt', 'w')
for line in response:
island = str(line)
f.write(town[2:len(town)-3])
f.write('\n')
f.close()
# ---- end of part 1
Last edited by a moderator: