mirror of
https://github.com/nikdoof/apishiv.git
synced 2025-12-13 07:32:16 +00:00
Working contacts page, though there's no link to the contacs page itself and the design is terribad
This commit is contained in:
@@ -1,135 +1,158 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from flask import Flask, render_template, request, redirect, flash, session, url_for
|
from flask import Flask, render_template, request, redirect, flash, session, url_for
|
||||||
from jinja2 import evalcontextfilter, Markup
|
from jinja2 import evalcontextfilter, Markup
|
||||||
from eveapi import EVEAPIConnection, Error
|
from eveapi import EVEAPIConnection, Error
|
||||||
from cache import DbCacheHandler
|
from cache import DbCacheHandler
|
||||||
from utils import mask_check
|
from utils import mask_check
|
||||||
|
|
||||||
eveapi = EVEAPIConnection(cacheHandler=DbCacheHandler())
|
eveapi = EVEAPIConnection(cacheHandler=DbCacheHandler())
|
||||||
app = Flask('apishiv')
|
app = Flask('apishiv')
|
||||||
|
|
||||||
API_ACCESS_TYPE = {
|
API_ACCESS_TYPE = {
|
||||||
0: 'Account Balance',
|
0: 'Account Balance',
|
||||||
1: 'Asset List',
|
1: 'Asset List',
|
||||||
2: 'Calendar Event Attendees',
|
2: 'Calendar Event Attendees',
|
||||||
3: 'Character Sheet',
|
3: 'Character Sheet',
|
||||||
4: 'Standings/Contacts (PCs/Corps/Alliances)',
|
4: 'Standings/Contacts (PCs/Corps/Alliances)',
|
||||||
5: 'Contact Notifications',
|
5: 'Contact Notifications',
|
||||||
6: 'Faction Warfare Stats',
|
6: 'Faction Warfare Stats',
|
||||||
7: 'Industry Jobs',
|
7: 'Industry Jobs',
|
||||||
8: 'Kill Log',
|
8: 'Kill Log',
|
||||||
9: 'Mail Bodies',
|
9: 'Mail Bodies',
|
||||||
10: 'Mailing Lists',
|
10: 'Mailing Lists',
|
||||||
11: 'Mail Messages',
|
11: 'Mail Messages',
|
||||||
12: 'Market Orders',
|
12: 'Market Orders',
|
||||||
13: 'Medals',
|
13: 'Medals',
|
||||||
14: 'Notifications',
|
14: 'Notifications',
|
||||||
15: 'Notification Texts',
|
15: 'Notification Texts',
|
||||||
16: 'Research Jobs',
|
16: 'Research Jobs',
|
||||||
17: 'Skill In Training',
|
17: 'Skill In Training',
|
||||||
18: 'Skill Queue',
|
18: 'Skill Queue',
|
||||||
19: 'Standings (NPC)',
|
19: 'Standings (NPC)',
|
||||||
20: 'Calendar Events',
|
20: 'Calendar Events',
|
||||||
21: 'Wallet Journal',
|
21: 'Wallet Journal',
|
||||||
22: 'Wallet Transactions',
|
22: 'Wallet Transactions',
|
||||||
23: 'Character Information',
|
23: 'Character Information',
|
||||||
24: 'Private Character Information',
|
24: 'Private Character Information',
|
||||||
25: 'Account Status',
|
25: 'Account Status',
|
||||||
26: 'Contracts',
|
26: 'Contracts',
|
||||||
}
|
}
|
||||||
|
|
||||||
def auth_from_session(session):
|
def auth_from_session(session):
|
||||||
return eveapi.auth(keyID=session['keyid'], vCode=session['vcode'])
|
return eveapi.auth(keyID=session['keyid'], vCode=session['vcode'])
|
||||||
|
|
||||||
@app.template_filter()
|
@app.template_filter()
|
||||||
@evalcontextfilter
|
@evalcontextfilter
|
||||||
def humanize(eval_ctx, n):
|
def humanize(eval_ctx, n):
|
||||||
if type(n) in [int, long, float]:
|
if type(n) in [int, long, float]:
|
||||||
s, ns = str(n).split('.')[0][::-1], ''
|
s, ns = str(n).split('.')[0][::-1], ''
|
||||||
for x in xrange(1,len(s)+1):
|
for x in xrange(1,len(s)+1):
|
||||||
ns = s[x-1]+ns
|
ns = s[x-1]+ns
|
||||||
if not x % 3 and len(s) > x: ns = ","+ns
|
if not x % 3 and len(s) > x: ns = ","+ns
|
||||||
if eval_ctx.autoescape: ns = Markup(ns)
|
if eval_ctx.autoescape: ns = Markup(ns)
|
||||||
return ns
|
return ns
|
||||||
|
|
||||||
@app.template_filter()
|
@app.template_filter()
|
||||||
@evalcontextfilter
|
@evalcontextfilter
|
||||||
def unixdate(eval_ctx, n):
|
def unixdate(eval_ctx, n):
|
||||||
ns = str(datetime.fromtimestamp(int(n)).strftime('%Y-%m-%d %H:%M:%S'))
|
ns = str(datetime.fromtimestamp(int(n)).strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
if eval_ctx.autoescape: ns = Markup(ns)
|
if eval_ctx.autoescape: ns = Markup(ns)
|
||||||
return ns
|
return ns
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def index():
|
def index():
|
||||||
if session.get('characters', None):
|
if session.get('characters', None):
|
||||||
return redirect(url_for('character_list'))
|
return redirect(url_for('character_list'))
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if not request.form['keyid'] or not request.form['vcode']:
|
if not request.form['keyid'] or not request.form['vcode']:
|
||||||
flash('Please provide a Key and verification code')
|
flash('Please provide a Key and verification code')
|
||||||
else:
|
else:
|
||||||
auth = eveapi.auth(keyID=request.form['keyid'], vCode=request.form['vcode'])
|
auth = eveapi.auth(keyID=request.form['keyid'], vCode=request.form['vcode'])
|
||||||
try:
|
try:
|
||||||
res = auth.account.ApiKeyInfo()
|
res = auth.account.ApiKeyInfo()
|
||||||
except Error as e:
|
except Error as e:
|
||||||
flash('Invalid KeyID/vCode, please try another')
|
flash('Invalid KeyID/vCode, please try another')
|
||||||
else:
|
else:
|
||||||
if res:
|
if res:
|
||||||
session['keyid'] = request.form['keyid']
|
session['keyid'] = request.form['keyid']
|
||||||
session['vcode'] = request.form['vcode']
|
session['vcode'] = request.form['vcode']
|
||||||
session['accessmask'] = res.key.accessMask
|
session['accessmask'] = res.key.accessMask
|
||||||
session['characters'] = {}
|
session['characters'] = {}
|
||||||
|
|
||||||
for c in res.key.characters:
|
for c in res.key.characters:
|
||||||
session['characters'][c.characterID] = c.characterName
|
session['characters'][c.characterID] = c.characterName
|
||||||
|
|
||||||
return redirect(url_for('character_list'))
|
return redirect(url_for('character_list'))
|
||||||
|
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
||||||
@app.route('/characters')
|
@app.route('/characters')
|
||||||
def character_list():
|
def character_list():
|
||||||
if not session.get('characters', None):
|
if not session.get('characters', None):
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
auth = auth_from_session(session)
|
auth = auth_from_session(session)
|
||||||
access = []
|
access = []
|
||||||
for id, name in API_ACCESS_TYPE.items():
|
for id, name in API_ACCESS_TYPE.items():
|
||||||
access.append((name, mask_check(session['accessmask'], id)))
|
access.append((name, mask_check(session['accessmask'], id)))
|
||||||
|
|
||||||
charinfo = {}
|
charinfo = {}
|
||||||
if mask_check(session['accessmask'], 3):
|
if mask_check(session['accessmask'], 3):
|
||||||
for id, name in session['characters'].items():
|
for id, name in session['characters'].items():
|
||||||
res = auth.char.CharacterSheet(characterID=id)
|
res = auth.char.CharacterSheet(characterID=id)
|
||||||
charinfo[id] = {'corporation': res.corporationName, 'balance': res.balance, 'sp_total': 0}
|
charinfo[id] = {'corporation': res.corporationName, 'balance': res.balance, 'sp_total': 0}
|
||||||
if hasattr(res, 'allianceName') and type(res.allianceName) == unicode:
|
if hasattr(res, 'allianceName') and type(res.allianceName) == unicode:
|
||||||
charinfo[id]['alliance'] = res.allianceName
|
charinfo[id]['alliance'] = res.allianceName
|
||||||
for skill in res.skills:
|
for skill in res.skills:
|
||||||
charinfo[id]['sp_total'] += skill.skillpoints
|
charinfo[id]['sp_total'] += skill.skillpoints
|
||||||
|
|
||||||
if mask_check(session['accessmask'], 23):
|
if mask_check(session['accessmask'], 23):
|
||||||
status = auth.account.AccountStatus()
|
status = auth.account.AccountStatus()
|
||||||
else:
|
else:
|
||||||
status = None
|
status = None
|
||||||
|
|
||||||
return render_template('characters.html', characters=session['characters'], access=access, charinfo=charinfo, status=status)
|
return render_template('characters.html', characters=session['characters'], access=access, charinfo=charinfo, status=status)
|
||||||
|
|
||||||
@app.route('/characters/<character_id>')
|
@app.route('/characters/<character_id>')
|
||||||
def character(character_id):
|
def character(character_id):
|
||||||
if mask_check(session['accessmask'], 3):
|
if mask_check(session['accessmask'], 3):
|
||||||
auth = auth_from_session(session)
|
auth = auth_from_session(session)
|
||||||
charinfo = auth.eve.CharacterInfo(characterID=character_id)
|
charinfo = auth.eve.CharacterInfo(characterID=character_id)
|
||||||
charsheet = auth.char.CharacterSheet(characterID=character_id)
|
charsheet = auth.char.CharacterSheet(characterID=character_id)
|
||||||
corp = eveapi.corp.CorporationSheet(corporationID=charsheet.corporationID)
|
corp = eveapi.corp.CorporationSheet(corporationID=charsheet.corporationID)
|
||||||
skilltree = eveapi.eve.SkillTree()
|
skilltree = eveapi.eve.SkillTree()
|
||||||
skilllist = {}
|
skilllist = {}
|
||||||
for skillgroup in skilltree.skillGroups:
|
for skillgroup in skilltree.skillGroups:
|
||||||
for skill in skillgroup.skills:
|
for skill in skillgroup.skills:
|
||||||
skilllist[skill['typeID']] = skill['typeName']
|
skilllist[skill['typeID']] = skill['typeName']
|
||||||
return render_template('character.html', character=charsheet, corp=corp, skilllist=skilllist, charinfo=charinfo)
|
return render_template('character.html', character=charsheet, corp=corp, skilllist=skilllist, charinfo=charinfo)
|
||||||
return redirect(url_for('characters'))
|
return redirect(url_for('characters'))
|
||||||
|
|
||||||
@app.route('/clear')
|
@app.route('/contacts/<character_id>')
|
||||||
def clear():
|
def contact(character_id):
|
||||||
session.clear()
|
if mask_check(session['accessmask'], 4):
|
||||||
return redirect(url_for('index'))
|
auth = auth_from_session(session)
|
||||||
|
contactlist = auth.char.ContactList(characterID=character_id)
|
||||||
|
contacts = []
|
||||||
|
for row in contactlist.contactList:
|
||||||
|
temp = {}
|
||||||
|
try:
|
||||||
|
temp['contactInfo'] = eveapi.eve.CharacterInfo(characterID=row.contactID)
|
||||||
|
except:
|
||||||
|
temp['contactInfo'] = False
|
||||||
|
temp['contactID'] = row.contactID
|
||||||
|
temp['contactName'] = row.contactName
|
||||||
|
temp['inWatchlist'] = row.inWatchlist
|
||||||
|
temp['standing'] = row.standing
|
||||||
|
contacts.append(temp)
|
||||||
|
return render_template('contacts.html', contactlist=contacts)
|
||||||
|
return redirect(url_for('characters'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/clear')
|
||||||
|
def clear():
|
||||||
|
session.clear()
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|||||||
37
apishiv/templates/contacts.html
Normal file
37
apishiv/templates/contacts.html
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
{% extends "layout.html" %}
|
||||||
|
{% block body %}
|
||||||
|
|
||||||
|
{% for contact in contactlist %}<div>
|
||||||
|
{% if contact.contactInfo %}
|
||||||
|
<img src="https://image.eveonline.com/Character/{{contact.contactID}}_64.jpg" style="float:left" /><span style="float:right">{{contact.contactName}}<br>{{contact.contactInfo.corporation}}<br>{{contact.contactInfo.alliance}}</span>
|
||||||
|
{% else %}
|
||||||
|
<img src="https://image.eveonline.com/Character/{{contact.contactID}}_64.jpg" style="float:left" /><span style="float:right">{{contact.contactName}}<br>{{contact.inWatchlist, contact.standing}}<br></span>
|
||||||
|
{% endif %}
|
||||||
|
</div><br>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function(){
|
||||||
|
$(".skill_heading")
|
||||||
|
.css("cursor", "pointer")
|
||||||
|
.attr("title", "Click to expand/collapse")
|
||||||
|
.click(function(){
|
||||||
|
$('tr[parent$=' + $(this).attr('id') + ']').toggle();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#openAll").bind("click", function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
$(".child").show();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#collapseAll").bind("click", function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
$(".child").hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('tr[parent]').hide();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user