Skip to content

Commit

Permalink
Init the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
psolyca committed Dec 24, 2019
0 parents commit fc1b7f4
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
install:
skip
script:
- ./sde_to_json.sh
before_deploy:
- if [[ -e gittag ]]; then
source ./gittag;
git tag ${gittag};
fi
deploy:
provider: releases
token: $GH_TOKEN
overwrite: true
file:
- mapRegions.json
- staStations.json
skip_cleanup: true
on:
tags: false
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# EVE Trade Resources

Automatic conversion of official database to JSON format usefull for EveTrade website.

Files available in release page :

* staStations.json
* mapRegions.json
20 changes: 20 additions & 0 deletions sde_to_json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

wget -O page https://developers.eveonline.com/resource/resources

currentrev=$(grep "https.*sde.*zip" page | awk -F '-' '{print $2}')
echo 'Current resources revision :' $currentrev
lastrev=$(git describe --abbrev=0 --tags)
if git rev-parse $currentrev >/dev/null 2>&1
then
if [[ $lastrev == $currentrev ]]
then
echo "Already lastest resources"
exit
fi
fi
echo 'Latest resources revision was :' $lastrev
echo 'Building resources files for new revision' $currentrev
python3 toJSON.py
echo "export gittag=$currentrev" > gittag

101 changes: 101 additions & 0 deletions toJSON.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# -*- coding: utf-8 -*-

import sys
import os
import glob
import requests
import zipfile
import io

from html.parser import HTMLParser


import yaml
try:
from yaml import CLoader as Loader
print('Using CLoader')
except ImportError:
from yaml import Loader
print('Using Python Loader')
import json

resources_link = "https://developers.eveonline.com/resource/resources"
map_regions = []

class MyHTMLParser(HTMLParser):

def handle_starttag(self, tag, attrs):
if tag == 'a':
for name, value in attrs:
if name == 'href' and 'tranquility' in value:
self.resources_file_link = value


def getResources():
if not os.path.exists('sde'):
resources_page = requests.get(resources_link)
parser = MyHTMLParser()
parser.feed(resources_page.content.decode())
print(parser.resources_file_link)
resources_file = requests.get(parser.resources_file_link)
if resources_file.ok:
resources_zip = zipfile.ZipFile(io.BytesIO(resources_file.content))
resources_zip.extractall()
else:
print("Folder already exists")

def importYaml():
print("Importing Universe Data")

if os.path.exists('invNames.json'):
print('Load JSON')
with open('invNames.json') as infile:
inv_names = json.load(infile)
else:
print('Load YAML')
with open(r'sde/bsd/invNames.yaml') as infile:
inv_names = yaml.load(infile, Loader = Loader)

with open('invNames.json', 'w') as outfile:
json.dump(inv_names, outfile)

print("Importing region static")
regions = glob.glob(os.path.join('sde', 'fsd', 'universe', '*', '*', 'region.staticdata'))
for region_file in regions:
region = {}
head, tail = os.path.split(region_file)
with open(region_file,'r') as region_yaml:
regiony = yaml.load(region_yaml, Loader = Loader)
if int(regiony['regionID']) > 11000000 and int(regiony['regionID']) < 14000000:
continue
print("Importing Region {}".format(head))
for item in inv_names:
if item['itemID'] == regiony['regionID']:
region_name = item['itemName']
break
region['regionID'] = regiony['regionID']
region['regionName'] = region_name
region['x'] = regiony['center'][0]
region['y'] = regiony['center'][1]
region['z'] = regiony['center'][2]
region['xMax'] = regiony['max'][0]
region['yMax'] = regiony['max'][1]
region['zMax'] = regiony['max'][2]
region['xMin'] = regiony['min'][0]
region['yMin'] = regiony['min'][1]
region['zMin'] = regiony['min'][2]
region['factionID'] = regiony.get('factionID')

map_regions.append(region)

map_region = sorted(map_regions, key = lambda i: i['regionID'])
with open('mapRegions.json', 'w') as outfile:
json.dump(map_region, outfile, separators = (',', ':'))

print("Converting stations data")
with open(r'sde/bsd/staStations.yaml') as infile:
with open('staStations.json', 'w') as outfile:
json.dump(yaml.load(infile, Loader = Loader), outfile, separators = (',', ':'))

getResources()
importYaml()

0 comments on commit fc1b7f4

Please sign in to comment.