Advertisement
Ashreen

Untitled

Jul 29th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 20.53 KB | None | 0 0
  1. import re
  2. from bs4 import BeautifulSoup
  3. import sqlite3
  4. import requests
  5. import math
  6. import decimal
  7.  
  8. #Scraping the updates
  9. #UPDATE STORAGE FUNCTIONS
  10.  
  11. def update_lumber_stock(my_soup):
  12.     lumber_storage = my_soup.find(id= "l1")
  13.     value_re = re.findall(r'\d', str(lumber_storage))
  14.     value_re.remove(value_re[0])
  15.     value = ''.join(value_re)
  16.     return value
  17.  
  18. def update_clay_stock(my_soup):
  19.     clay_storage = my_soup.find(id= "l2")
  20.     value_re = re.findall(r'\d', str(clay_storage))
  21.     value_re.remove(value_re[0])
  22.     value = ''.join(value_re)
  23.     return value
  24.  
  25. def update_iron_stock(my_soup):
  26.     iron_storage = my_soup.find(id= "l3")
  27.     value_re = re.findall(r'\d', str(iron_storage))
  28.     value_re.remove(value_re[0])
  29.     value = ''.join(value_re)
  30.     return value
  31.  
  32. def update_crop_stock(my_soup):
  33.     crop_storage = my_soup.find(id= "l4")
  34.     value_re = re.findall(r'\d', str(crop_storage))
  35.     value_re.remove(value_re[0])
  36.     value = ''.join(value_re)
  37.     return value
  38.  
  39. def update_warehouse(my_soup):
  40.     warehouse_storage = my_soup.find(id="stockBarWarehouse")
  41.     value_re = re.findall(r'\d', str(warehouse_storage))
  42.     value = ''.join(value_re)
  43.     return value
  44.  
  45. def update_granary(my_soup):
  46.     granary_storage = my_soup.find(id="stockBarGranary")
  47.     value_re = re.findall(r'\d', str(granary_storage))
  48.     value = ''.join(value_re)
  49.     return value
  50.  
  51. #UPDATE PRODUCTION FUNCTIONS      
  52.  
  53. def update_lumber_prod(my_soup):
  54.     soup_lumber_prod = my_soup.find(href="production.php?t=1")
  55.     lumber_prod = re.findall(r'\d+', str(soup_lumber_prod))
  56.     return lumber_prod[1]
  57.    
  58. def update_clay_prod(my_soup):
  59.     soup_clay_prod = my_soup.find(href="production.php?t=2")
  60.     clay_prod = re.findall(r'\d+', str(soup_clay_prod))
  61.     return clay_prod[1]
  62.  
  63. def update_iron_prod(my_soup):
  64.     soup_iron_prod = my_soup.find(href="production.php?t=3")
  65.     iron_prod = re.findall(r'\d+', str(soup_iron_prod))
  66.     return iron_prod[1]
  67.  
  68. def update_crop_prod(my_soup):
  69.     soup_crop_prod = my_soup.find(href="production.php?t=5")
  70.     crop_prod = re.findall(r'\d+', str(soup_crop_prod))
  71.     return crop_prod[3]
  72.  
  73. #UPDATE BUILDINGS FUNCTIONS
  74.  
  75. def get_spot_info(session, server):
  76.     value = []
  77.     for x in range(1, 39):
  78.  
  79.         html = session.get("http://{0}/build.php?id={1}".format(server, x))
  80.         unicodeData = html.text
  81.         unicodeData.encode('ascii', 'ignore')
  82.         soup = BeautifulSoup(unicodeData, 'html.parser')
  83.         scrape = soup.find(id="build")
  84.         spot = re.findall(r'\d+', str(scrape))
  85.         if spot[0] == "0":
  86.             spot[1] = 0
  87.         triple_tup = ("1", x, spot[0], spot[1])
  88.         value.append(triple_tup)
  89.  
  90.     return value
  91.  
  92. def create_buildings_list():
  93.     value = []
  94.     for x in range(0,42):
  95.  
  96.         name = ["Empty field","Woodcutter","Clay Pit","Iron Mine","Cropland","Sawmill",
  97.                 "Brickyard","Iron Foundry","Grain Mill","Bakery","Warehouse",
  98.                 "Granary", "0", "Smithy","Tournament Square","Main Building","Rally Point",
  99.                 "Marketplace","Embassy","Barracks","Stable","Workshop",
  100.                 "Academy","Cranny","Town Hall","Residence","Palace",
  101.                 "Treasury","Trade Office","Great Barracks","Great Stable",
  102.                 "City Wall","Earth Wall","Palisade","Stonemason's Lodge","Brewery",
  103.                 "Trapper","Hero's Mansion","Great Warehouse","Great Granary",
  104.                 "Wonder of the World","Horse Drinking Trough"]
  105.         triple_tup = (x, name[x], 0, 0, 0)
  106.         value.append(triple_tup)
  107.  
  108.     return value
  109.  
  110. def buildings():
  111.     conn = sqlite3.connect('travdate.sqlite')
  112.     cursor = conn.cursor()
  113.     cursor.execute('''SELECT gid, name FROM buildings''')
  114.     data2 = cursor.fetchall()
  115.  
  116.     buildings_list = []
  117.  
  118.     for row in data2:
  119.         buildings_list.append(row[1].encode('ascii', 'ignore'))
  120.  
  121.     return buildings_list
  122.  
  123. #SQLITE execute
  124. def sqlite_update(session, server):
  125.    
  126.     html = session.get('http://{0}/dorf1.php'.format(server))
  127.     unicodeData = html.text
  128.     unicodeData.encode('ascii', 'ignore')
  129.     my_soup = BeautifulSoup(unicodeData, 'html.parser')
  130.  
  131.     #SQLITE code
  132.     conn = sqlite3.connect('travdate.sqlite')
  133.     cur = conn.cursor()
  134.  
  135.     cur.executescript('''
  136.    DROP TABLE IF EXISTS resources;
  137.    DROP TABLE IF EXISTS storage;
  138.    DROP TABLE IF EXISTS spots;
  139.    DROP TABLE IF EXISTS buildings;
  140.    DROP TABLE IF EXISTS map_info;
  141.  
  142.    CREATE TABLE resources (
  143.        village_id   INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
  144.        lumber       INTEGER NOT NULL,
  145.        clay         INTEGER NOT NULL,
  146.        iron         INTEGER NOT NULL,
  147.        crop         INTEGER NOT NULL,
  148.        lumber_prod  INTEGER NOT NULL,
  149.        clay_prod    INTEGER NOT NULL,
  150.        iron_prod    INTEGER NOT NULL,
  151.        crop_prod    INTEGER NOT NULL
  152.    );
  153.  
  154.    CREATE TABLE storage (
  155.        village_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
  156.        warehouse   INTEGER NOT NULL,
  157.        granary    INTEGER NOT NULL
  158.  
  159.    );
  160.  
  161.    CREATE TABLE spots (
  162.        village_id INTEGER NOT NULL,
  163.        id INTEGER NOT NULL,
  164.        gid   INTEGER NOT NULL,
  165.        level   INTEGER NOT NULL
  166.  
  167.    );
  168.  
  169.    CREATE TABLE buildings (
  170.        gid INTEGER NOT NULL PRIMARY KEY UNIQUE,
  171.        name TEXT NOT NULL,
  172.        req1 INTEGER NOT NULL,
  173.        req2 INTEGER NOT NULL,
  174.        req3 INTEGER NOT NULL
  175.    );
  176.  
  177.    CREATE TABLE map_info (
  178.        village_id INTEGER NOT NULL,
  179.        type TEXT NOT NULL,
  180.        x INTEGER NOT NULL,
  181.        y INTEGER NOT NULL,
  182.        distance INTEGER NOT NULL,
  183.        inhabitants TEXT,
  184.        player TEXT,
  185.        village TEXT,
  186.        alliance TEXT,
  187.        nation TEXT,
  188.        field_type TEXT NOT NULL
  189.    );
  190.  
  191.    CREATE TABLE IF NOT EXISTS build_queue (
  192.        id         INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
  193.        village_id INTEGER NOT NULL,
  194.        gid   INTEGER NOT NULL,
  195.        aid    INTEGER NOT NULL,
  196.        level  INTEGER NOT NULL,
  197.        active INTEGER NOT NULL,
  198.        timer INTEGER NOT NULL
  199.        )
  200.    ''')
  201.  
  202.     cur.execute('''INSERT INTO resources(lumber, clay, iron, crop, lumber_prod,
  203.    clay_prod, iron_prod, crop_prod) VALUES (?, ?, ?, ?, ?, ?, ?, ?)''',
  204.     (update_lumber_stock(my_soup), update_clay_stock(my_soup), update_iron_stock(my_soup),
  205.         update_crop_stock(my_soup), update_lumber_prod(my_soup),update_clay_prod(my_soup),
  206.         update_iron_prod(my_soup), update_crop_prod(my_soup)))
  207.  
  208.     cur.execute('''INSERT INTO storage(warehouse, granary) VALUES(?, ?)''',
  209.         (update_warehouse(my_soup), update_granary(my_soup)))
  210.  
  211.     values_to_insert = get_spot_info(session, server)
  212.  
  213.     cur.executemany('''
  214.        INSERT INTO spots ('village_id','id', 'gid', 'level')
  215.        VALUES (?, ?, ?, ?)''', values_to_insert)
  216.  
  217.     values_to_insert = create_buildings_list()
  218.  
  219.     cur.executemany('''
  220.        INSERT INTO buildings ('gid', 'name', 'req1', 'req2', 'req3')
  221.        VALUES (?, ?, ?, ?, ?)''', values_to_insert)
  222.    
  223.     conn.commit()
  224.  
  225. def upgrade_link(session, server, building_id):
  226.  
  227.     html = session.get("http://{0}/build.php?id={1}".format(server, building_id))
  228.     unicodeData = html.text
  229.     soup = BeautifulSoup(unicodeData, 'html.parser')
  230.  
  231.     my_re = re.findall(r'dorf..php\?a=...............', str(soup))
  232.     re_str = my_re[0]
  233.     re_list = list(re_str)
  234.     re_list.pop(15)
  235.     re_list.pop(15)
  236.     re_list.pop(15)
  237.     re_list.pop(15)
  238.     re_str = "".join(re_list)
  239.     return re_str
  240.  
  241. def is_building(village_id, session, server):
  242.     # This function inserts build_info into sqlite, or returns False
  243.     try:
  244.         #SQLITE code
  245.         conn = sqlite3.connect('travdate.sqlite')
  246.         cur = conn.cursor()
  247.         #request and soup
  248.         req = session.get('http://{0}/dorf2.php'.format(server))
  249.         unicodeData = req.text
  250.         unicodeData.encode('ascii', 'ignore')
  251.         soup = BeautifulSoup(unicodeData, 'html.parser')
  252.         #Time left in seconds
  253.         time_left = soup.find("div", {"class" : "buildDuration"})
  254.         time_left = list(time_left)[1]
  255.         time_left = re.findall(r"\d+", str(time_left))
  256.         time_left = time_left[0]
  257.         #level, gid, aid
  258.         level_info = re.findall(r"\"stufe\":..", str(soup))[0]
  259.         level_info = re.findall(r"\d+", level_info)[0]
  260.         gid_info = re.findall(r"\"gid\":\"....", str(soup))[0]
  261.         gid_info = re.findall(r"\d+", gid_info)[0]
  262.         aid_info = re.findall(r"\"aid\":\"....", str(soup))[0]
  263.         aid_info = re.findall(r"\d+", aid_info)[0]
  264.         #SQL execute
  265.         cur.execute('''INSERT INTO build_queue(village_id, gid, aid, level, active, timer)
  266.        VALUES(?, ?, ?, ?, ?, ?)''',
  267.         (village_id, gid_info, aid_info, level_info, "1", time_left))
  268.         conn.commit()
  269.         return True
  270.     except TypeError:    
  271.         return False
  272.  
  273. #2 scpravnute subory, soup a js
  274. #Transform coordinates into distance between them
  275. def transform_coordinates(a,b):
  276.     if a < 0:
  277.         if b < 0:
  278.             base = abs(a) - abs(b)
  279.         elif b > 0:
  280.             base = abs(a) + abs(b)
  281.         else:
  282.             base = abs(a)
  283.     elif a > 0:
  284.         if b < 0:
  285.             base = abs(a) + abs(b)
  286.         elif b > 0:
  287.             base = abs(a) - abs(b)
  288.         else:
  289.             base = abs(a)
  290.     else:
  291.         base = abs(b)
  292.     return abs(base)
  293.  
  294. #Calculate distance between 2 tiles on the map
  295. def get_tile_distance(x1,y1,x2,y2):
  296.     """
  297.    Berie ako argumenty coordinaty dvoch policok,
  298.    a vypocita vyslednu vzdialenost.
  299.    """
  300.  
  301.     if x1 == x2:
  302.         return transform_coordinates(y1,y2)
  303.     elif y1 == y2:
  304.         return transform_coordinates(x1,x2)
  305.     elif x1 == x2 and y1 == y2:
  306.         return 0
  307.     else:
  308.         basex = transform_coordinates(x1,x2)
  309.         basey = transform_coordinates(y1,y2)
  310.         base = basex*basex + basey*basey
  311.         base = math.sqrt(base)
  312.         decimal.getcontext().prec = 7
  313.         base = decimal.Decimal(base).quantize(
  314.             decimal.Decimal('0.0'),
  315.             rounding=decimal.ROUND_HALF_UP)
  316.         return base
  317.  
  318.  
  319. def get_ajax_token(session, server):
  320.     """
  321.    Bere ako argument session,
  322.    spravy request, a returnuje ajax_id.
  323.    """
  324.  
  325.     r1 = session.get('http://{0}/dorf2.php'.format(server))
  326.     unicodeData = r1.text
  327.     unicodeData.encode('ascii', 'ignore')
  328.     soup = BeautifulSoup(unicodeData, 'html.parser')
  329.     ajax_id = re.findall(r"window\.ajaxToken\s=.*", str(soup))
  330.     ajax_id = str(ajax_id).split("'")
  331.     ajax_id = ajax_id[1]
  332.     print ajax_id
  333.     return ajax_id
  334.  
  335. def get_tile(x,y,session,server):
  336.  
  337.     """
  338.    Bere ako argumenty coordinaty policka,
  339.    Spravy kompletny request a login,
  340.    returnuje cele html ako string.
  341.    """
  342.     payload = {'cmd': "viewTileDetails",'x': x, 'y': y,  'ajaxToken': get_ajax_token(session, server)}
  343.     req = session.post('http://{0}/ajax.php?cmd=viewTileDetails'.format(server), data=payload)
  344.     file = open("javascript.txt", "w+")
  345.     file.write(req.content)
  346.     file.close
  347.     return req.content
  348.  
  349.  
  350. def make_file(data, file_name):
  351.  
  352.     file_name = open(file_name, "w+")
  353.     file_name.write(data)
  354.     file_name.close()
  355.  
  356. def make_soup(x,y,session,server):
  357.  
  358.     """
  359.    Tato funkcia vola funkcia get_tile(), ktora robi request
  360.    Spravy nam textovy subor ajaxsoup.txt, scrapnute html.
  361.    + returnuje soup, lebo sa pouziva v inych funkciach.
  362.    """
  363.     tile_info = get_tile(x,y,session,server)
  364.     soup = BeautifulSoup(tile_info, 'html.parser')
  365.     soup_file = soup.encode('ascii', 'ignore')
  366.     make_file(soup_file, "ajaxsoup.txt")
  367.     return soup
  368.    
  369. #villages
  370. #3, 3, 3, 9 = village-1
  371. #3, 4, 5, 6 = village-2 ,
  372. #4, 4, 4, 6 = village-3
  373. #4, 5, 3, 6 = village-4
  374. #5, 3, 4, 6 = village-5
  375. #1, 1, 1, 15 =village-6
  376. #4, 4, 3, 7 = village-7
  377. #3, 4, 4, 7 = village-8
  378. #4, 3, 4, 7 = village-9
  379. #3, 5, 4, 6 = village-10
  380. #4, 3, 5, 6 = village-11
  381. #5, 4, 3, 6 = village-12
  382.  
  383. #oasis
  384. #50% clay            = oasis-8-
  385. #50% iron            = oasis-12-
  386. #25% lumber,crop     = oasis-3-
  387. #50% crop            = oasis-15-
  388. #25% crop            = oasis-14-
  389. #50% lumber          = oasis-4-
  390. #25% iron, crop      = oasis-11-
  391.  
  392. #25% lumber          = oasis-2-
  393. #25% clay            = oasis-6-
  394. #25% iron            = oasis-10-
  395. #25% clay, crop      = oasis-7-
  396.  
  397.  
  398. def get_tile_type():  # tato funkcia returnuje tuple ("village", 9) , alebo (oasis, 2), !!POZOR!!
  399.    
  400.     #Ak je to village, treba zistit ci je to hrac, h1 tag je meno dediny.  , + obyvatelia, vzdialenost, aliancia.
  401.  
  402.     tile_type_list = ["village", "oasis", "landscape"]
  403.  
  404.     file = open("javascript.txt", "r+")
  405.     soup = BeautifulSoup(file, "html.parser")
  406.     vlg_re = r"<div\sclass='\\\"village'\sid='\\\"tileDetails\\\"'\svillage-.."
  407.     village_re = re.findall(vlg_re, str(soup))
  408.     oas_re = r"<div\sclass='\\\"oasis'\sid='\\\"tileDetails\\\"'\soasis-.."
  409.     oasis_re = re.findall(oas_re, str(soup))
  410.     land_re = r"<div\sclass='\\\"landscape'\sid='\\\"tileDetails\\\"'\slandscape"
  411.     landscape_re = re.findall(land_re, str(soup))
  412.     re_list = [village_re, oasis_re, landscape_re]
  413.  
  414.     for regex in re_list:
  415.         if regex:
  416.             the_re = regex
  417.  
  418.     try:
  419.         final_re = re.findall(r"\d+", str(the_re))
  420.         tile_id = final_re[0]
  421.  
  422.         for x in tile_type_list:
  423.             if x in the_re[0]:
  424.  
  425.                 return (x, tile_id)
  426.     except IndexError:
  427.         return ("landscape", "0")
  428.  
  429.  
  430. # tato funkcia vezme ako argument get_tile_type(), returnuje , typ policka + basic staty
  431. def get_tile_info(tile_info):
  432.  
  433.     villages = {"1": [3,3,3,9], "2": [3,4,5,6], "3": [4,4,4,6], "4": [4,5,3,6], "5": [5,3,4,6],
  434.     "6": [1,1,1,15], "7": [4,4,3,7], "8": [3,4,4,7], "9": [4,3,4,7], "10": [3,5,4,6],
  435.     "11": [4,3,5,6], "12": [5,4,3,6]}
  436.  
  437.     oasis = {"2": "lumber 25%", "6": "clay 25%", "10": "iron 25%", "14": "crop 25%",
  438.     "8": "clay 50%", "12": "iron 50%", "4": "lumber 50%", "15": "crop 50%",
  439.     "3": "lumber+crop 25%", "11": "iron+crop 25%", "7": "clay+crop 25%"}
  440.  
  441.     if tile_info[0] == "village":
  442.         file = open("javascript.txt", "r+")
  443.         soup = BeautifulSoup(file, "html.parser")
  444.         return tile_info[0], villages[tile_info[1]]
  445.    
  446.     if tile_info[0] == "oasis":
  447.         return tile_info[0], oasis[tile_info[1]], find_monsters()
  448.  
  449.     if tile_info[0] == "landscape":
  450.         return "landscape"
  451.     else:
  452.         print "no match"
  453.  
  454.  
  455.  
  456. def find_monsters():  #neukazuje to ake su to monstra, ked to bude treba tak dorobit.
  457.     """
  458.    returns monsters @oasis, as a list.[7, 5, 5], this funkcion is used in get_tile_info()
  459.    in current state, it takes data from text document that has already been scraped
  460.    """
  461.     try:
  462.         file = open("javascript.txt", "r+")
  463.         #file = open("oasismonsters.txt", "r+")
  464.         data = file.read()
  465.         file.close()
  466.  
  467.         oasis_monsters = re.findall(r"<img class=\\\"unit.{1250}", str(data))
  468.         oasis_monsters = oasis_monsters[0].split(" ")
  469.         oasis_monsters = filter(None, oasis_monsters)
  470.         monster_list = []
  471.         for string in oasis_monsters:
  472.             if len(string) <3:
  473.                 monster_list.append(string)
  474.  
  475.         return monster_list
  476.     except IndexError:
  477.         return "Empty"
  478.  
  479.  
  480. def is_player(x,y,session,server): # Tato funkcia zisti ci je na policku dedina alebo je prazdne, ak je prazdne vrati False, ale je tam dedina True.
  481.  
  482.     # Sprav tu if aby to zistilo ci tam je dedina, ak ano return True
  483.     data = make_soup(x,y,session,server)
  484.     try:
  485.         village_name = re.findall(r"<h1>.{20}", str(data))
  486.         vllg_name = village_name[0].split("\\")
  487.         vllg_name = vllg_name[0].split("<h1>")
  488.         vllg_name = vllg_name[1]
  489.  
  490.         if vllg_name:
  491.             return True
  492.         else:
  493.             return False
  494.     except IndexError:
  495.         return False
  496.  
  497. def get_complex_info(my_x, my_y, x, y,session,server):
  498.     #tato funkcia vezme ako argumenty: is_player funkciu, aj je is_player True,
  499.     #returne to info o hracovej dedine, ak je False returne to info o policku
  500.     distance = get_tile_distance(my_x, my_y, x, y) # distance chceme tak ci tak
  501.     player = is_player(x,y,session,server)
  502.  
  503.     file = open("javascript.txt", "r")
  504.     data = file.read()
  505.     file.close()
  506.    
  507.     dict_values = {"type": "",
  508.                     "x": 0,
  509.                     "y": 0,
  510.                     "distance": distance,
  511.                     "inhabitants": "",
  512.                     "player": "",
  513.                     "village_name": "",
  514.                     "alliance": "",
  515.                     "nation": "",
  516.                     "field_type": ""
  517.                     }  
  518.  
  519.     if player == True: #ak je tam dedina nejakeho hraca
  520.         #village_name
  521.         try:
  522.             village_name = re.findall(r"<h1>.{20}", data)
  523.             vllg_name = village_name[0].split("\\")
  524.             vllg_name = vllg_name[0].split("<h1>")
  525.             vllg_name = vllg_name[1]
  526.             #player name
  527.             player_name = re.findall(r"<a\shref=\\\"spieler\.php\?uid=....\\\">.{10}", data)
  528.             player_name = player_name[0].split("\\\">")
  529.             player_name = player_name[1].split("<")
  530.             player_name = player_name[0]
  531.             #population
  532.             population = re.findall(r"<a\shref=\\\"spieler\.php\?uid=....\\\">.{100}", data)[0]
  533.             population = population.split("<td>")
  534.             population = population[1].split("<")
  535.             population = population[0]
  536.             #alliance
  537.             alliance = re.findall(r"<a\shref=\\\"allianz.php\?aid=.{10}", data)
  538.             alliance = alliance[0].split(">")
  539.             alliance = alliance[1].split("<")
  540.             alliance = alliance[0]
  541.             #nation
  542.             nation = re.findall(r"class=\\\"first\\\">.{60}", data)
  543.             nation = nation[0].split("<td>")
  544.             nation = nation[1].split("<")
  545.             nation = nation[0]
  546.  
  547.            
  548.             #if it's a village controlled by a player
  549.             dict_values = {"type": get_tile_type()[0],
  550.                            "x": x,
  551.                            "y": y,
  552.                            "distance": distance,
  553.                            "inhabitants": population,
  554.                            "player": player_name,
  555.                            "village_name": vllg_name,
  556.                            "alliance": alliance,
  557.                            "nation": nation,
  558.                            "field_type": get_tile_info(get_tile_type())[1]
  559.                         }
  560.         # if its an Oasis
  561.         except IndexError:
  562.             dict_values["type"] = get_tile_type()[0]
  563.             dict_values["x"] = x
  564.             dict_values["y"] = y
  565.             dict_values["inhabitants"] = find_monsters()
  566.             dict_values["player"] = ""
  567.             dict_values["alliance"] = ""
  568.             dict_values["nation"] = ""
  569.             dict_values["field_type"] = get_tile_info(get_tile_type())[1]
  570.         return dict_values
  571.  
  572.     if player == False:
  573.         #if its an empty village
  574.         dict_values["type"] = get_tile_type()[0]
  575.         dict_values["x"] = x
  576.         dict_values["y"] = y
  577.         dict_values["inhabitants"] = 0
  578.         dict_values["player"] = ""
  579.         dict_values["alliance"] = ""
  580.         dict_values["nation"] = ""
  581.         dict_values["field_type"] = get_tile_info(get_tile_type())[1]
  582.  
  583.         return dict_values
  584.     else:
  585.         return False
  586.  
  587.  
  588. def map_scan(centerx, centery, scope, session, server):
  589.     i = centerx - scope
  590.     j = centery + scope
  591.     conn = sqlite3.connect('travdate.sqlite')
  592.     cur = conn.cursor()
  593.  
  594.     print i,j
  595.  
  596.     while(i < i+7):
  597.         while(j > j-7):
  598.             if i == centerx and j == centery:
  599.                 print "haha"
  600.             else:
  601.                 map_info_values = get_complex_info(centerx, centery, i, j, session, server)
  602.                 print map_info_values
  603.                 if map_info_values == False:
  604.                     print "skip"
  605.                 else:
  606.                     cur.execute('''INSERT INTO map_info(type, x, y, distance, inhabitants,
  607.                        player, village, alliance, nation, field_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
  608.                         (map_info_values["type"], map_info_values["x"],map_info_values["y"],
  609.                         map_info_values["distance"], map_info_values["inhabitants"],
  610.                         map_info_values["player"], map_info_values["village_name"],
  611.                         map_info_values["alliance"], map_info_values["nation"],
  612.                         map_info_values["field_type"]))
  613.             j = j - 1
  614.         i = i + 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement