Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #TODO: Check of blueprint al bestaat voordat deze toegevoegd wordt
- from django.db import models
- class Blueprint(models.Model):
- """
- Table that yields all my owned blueprints and their values.
- Some fields are later needed when eve api gets used.
- This will become importable from a .csv file
- """
- bp_eve_id = models.IntegerField() #Let op!Blueprint ID van eve, verwijst naar foreignkey in eve tables
- name = models.CharField(max_length=127)
- blueprint_group = models.CharField(max_length=127)
- material_efficiency = models.IntegerField()
- production_efficiency = models.IntegerField()
- blueprint_original = models.BooleanField()
- """Not imported data"""
- price = models.IntegerField(default=0)
- tier2 = models.BooleanField(default=False)
- def __unicode__(self):
- return self.name
- class Order(models.Model):
- """
- Holds the orders which can be more then 1 product
- """
- ingame = models.CharField(max_length=127)
- creation_date = models.DateTimeField()
- accepted = models.BooleanField(default=False)
- production_time = models.IntegerField()
- class SingleOrder(models.Model):
- oder_id = models.ForeignKey(Order)
- blueprint_id = models.ForeignKey(Blueprint)
- quantity = models.IntegerField()
- suggested_price = models.IntegerField()
- def import_blueprints(file_name):
- """
- Adds a new added .csv file (exported from Isk Per Hour) and adds all owned blueprints to blueprints
- """
- open_file = open(file_name, 'r')
- for line in open_file:
- row = line.split(',')
- reetkever = row[3].split(' Blueprint')
- if Blueprint.objects.filter(name=reetkever[0]).count() > 0:
- pass
- elif row[6] == "True":
- bp_id = row[1]
- bp_name = row[3].split(' Blueprint')
- bp_group = row[2].split(' Blueprint')
- bp_me = row[4]
- bp_pe = row[5]
- if row[8] == 'BPO':
- bp_original = True
- else:
- bp_original = False
- bp = Blueprint(
- bp_eve_id = bp_id,
- name = bp_name[0],
- blueprint_group = bp_group[0],
- material_efficiency = bp_me,
- production_efficiency = bp_pe,
- blueprint_original = bp_original
- )
- bp.save()
- else:
- pass
- open_file.close()
Advertisement
Add Comment
Please, Sign In to add comment