def gen_creature_cards(browser, number_of_cards=1): browser.execute_script("createJS('classNames.js')") WebDriverWait(browser, 10).until( EC.presence_of_all_elements_located( (By.XPATH, "//span[@id='options']/input"))) for i in range(number_of_cards): browser.execute_script("mynameGen(1)") names = WebDriverWait(browser, 10).until( EC.presence_of_all_elements_located( (By.XPATH, "//ul[@id='myresult']/li"))) for name in names: card_title = name.text if Card.objects.filter(title=card_title).first() is None: card = Card() card.type = "creature" card.cardset = "set10" card.title = card_title card.hp = randint(1, 8) card.attack = randint(1, 6) card.mana = randint(1, 7) card.save() card.portrait = generate_portrait("{0}.png".format(card.key)) card.save() print("CreatureCard created: {0}".format(card.title))
def setUp(self): t = Tool(id=1, name='test_tool', status=1, status_message='working ok') t.save() u = User(id=1, name='Test user', subscribed=True) u.save() c = Card(card_id='12345678', user=u) c.save()
def setUp(self): t = Tool(id=1, name='test_tool', status=1, status_message='working ok') t.save() v = VendItem(name='test_item', price=55) v.save() v = VendItem(name='test_item2', price=600) v.save() m = MachineItem(item=VendItem.objects.get(name='test_item'), tool=Tool.objects.get(pk=1), position=1, stock=0) m.save() m = MachineItem(item=VendItem.objects.get(name='test_item2'), tool=Tool.objects.get(pk=1), position=2, stock=1) m.save() m = MachineItem(item=VendItem.objects.get(name='test_item'), tool=Tool.objects.get(pk=1), position=3, stock=7) m.save() users = ( # user 1 has 2 cards, and is a maintainer (1, 'user1a', '00112233445566', True, 99999), (1, 'user1b', 'aabbccdd', True, 99999), # a user (2, 'user2', '22222222', True, 0), # subscribed, but not a user (3, 'user3', '33333333', True, 77), # exists, but not is not subscribed (4, 'user4', '44444444', False, 555), ) for id, name, card, subscribed, balance in users: self.__dict__[name] = card try: u = User.objects.get(pk=id) u.save() c = Card(card_id=card, user=u) c.save() except ObjectDoesNotExist: u = User(id=id, name=name, subscribed=subscribed, balance=balance) u.save() c = Card(card_id=card, user=u) c.save()
def setUp(self): t = Tool(id=1, name='test_tool', status=1, status_message='working ok') t.save() u = User(id=1, name='Test user', subscribed=True) u.save() c = Card(card_id='12345678', user=u) c.save() # make user 1 a user for tool 1 p = Permission(user=User.objects.get(pk=1), permission=1, tool=Tool.objects.get(pk=1), addedby=User.objects.get(pk=1)) p.save()
def gen_spell_cards(browser, number_of_cards=1): for i in range(number_of_cards): browser.execute_script("createJS('spellNames.js')") names = WebDriverWait(browser, 10).until( EC.presence_of_all_elements_located( (By.XPATH, "//ul[@id='myresult']/li"))) print("Collecting Names: {0} {1}".format(i, len(names))) for name in names: card_title = name.text if Card.objects.filter(title=card_title).first() is None: card = Card() card.type = "spell" card.cardset = "set10" card.title = card_title card.hp = 0 card.dp = 0 card.mana = randint(1, 6) card.save() card.portrait = generate_portrait("{0}.png".format(card.key)) card.save() print("SpellCard created: {0}".format(card.title))
def handle(self, *args, **options): path = options['path'] if not os.path.exists(path): raise CommandError('Can\'t find %s' % (path)) sr = os.stat(path) if sr[stat.ST_SIZE] == 0: raise CommandError('%s is zero size, not using it.' % (path)) fh = open(path, 'r') jdata = json.load(fh) fh.close() if len(jdata) == 0: raise CommandError('%s has no entries, not using it.' % (path)) for u in jdata: # {u'perms': [], u'subscribed': False, u'gladosfile': u'zz', u'nick': u'notsubscribed', u'cards': [u'44444444'], u'id': u'4'} eu = None try: eu = User.objects.get(pk=u['id']) except ObjectDoesNotExist: pass if eu: # update nick and subscription eu.name = u['nick'] eu.subscribed = u['subscribed'] #gladosfile should be empty rather than null in this DB if u['gladosfile'] is not None: eu.gladosfile = u['gladosfile'] else: eu.gladosfile = "" ecs = eu.card_set.all() for ec in ecs: # delete cards that have gone away if ec.card_id not in u['cards']: ec.delete() for c in u['cards']: # add new cards if c not in [x.card_id for x in ecs]: try: if len(c) <= 14: co = Card(card_id=c, user=eu) co.save() else: self.stdout.write( "for %s, card id %s is too long" % (eu, c)) except DataError as e: self.stdout.write(u) self.stdout.write(e) self.stdout.write( "error adding new card for %s, card too long? %s" % (eu, c)) eu.save() else: with transaction.atomic(): nu = User(id=int(u['id']), name=u['nick'], subscribed=u['subscribed']) #gladosfile should be empty rather than null in this DB if u['gladosfile'] is not None: nu.gladosfile = u['gladosfile'] try: nu.save() except Exception as e: self.stdout.write("blah.") self.stdout.write(e, type(e)) self.stdout.write(u) for c in u['cards']: try: # the card already exist? ec = Card.objects.get(card_id=c) # bother, it does. # Which of the 2 users is subscribed? if not u['subscribed']: self.stdout.write( "skipping card %s, it's already in the db and this user is not subscribed" % (c, )) continue else: # darn, maybe the other user is not subscribed? if not ec.user.subscribed: self.stdout.write( "card %s is already in the db for %s, but they are not subscribed so i'm deleting the card" % (c, ec.user)) ec.delete() else: self.stdout.write( "panic: card id %s is in use by 2 users: %s and %s" % (c, ec.user, nu)) except ObjectDoesNotExist: pass except Exception as e: self.stdout.write(u) self.stdout.write("lol wtf", e) try: if len(c) <= 14: co = Card(card_id=c, user=nu) co.save() else: self.stdout.write( "for %s, card id %s is too long" % (nu, c)) except Exception as e: self.stdout.write(e, type(e)) PrintFrame() self.stdout.write(u) self.stdout.write(nu) continue try: nu.save() except Exception as e: self.stdout.write(e, type(e)) PrintFrame() self.stdout.write(u) self.stdout.write(nu) carddb_by_id = {} for u in jdata: # {u'perms': [], u'subscribed': False, u'gladosfile': u'zz', u'nick': u'notsubscribed', u'cards': [u'44444444'], u'id': u'4'} carddb_by_id[int(u['id'])] = u # loop through all acnode users and check that they exist in the carddb. for au in User.objects.all(): if au.id not in carddb_by_id: self.stdout.write( "user with id %d is in the local db, but not in carddb.json, unsubscribeing them and removing their cards" % (au.id)) # remove cards cs = au.card_set.all() for c in cs: c.delete() # set status to unsubscribed au.subscribed = False # we don't want to delete them cos of 'on cascade delete' stuffs, and there account might get re-activated au.save()
def setUp(self): t = Tool(id=1, name='test_tool', status=1, status_message='working ok') t.save() t = Tool(id=2, name='other test tool', status=0, status_message='Out of action') t.save() users = ( # user 1 has 2 cards, and is a maintainer (1, 'user1a', '00112233445566', True), (1, 'user1b', 'aabbccdd', True), # a user (2, 'user2', '22222222', True), # subscribed, but not a user (3, 'user3', '33333333', True), # exists, but not is not subscribed (4, 'user4', '44444444', False), ) for id, name, card, subscribed in users: self.__dict__[name] = card try: u = User.objects.get(pk=id) u.save() c = Card(card_id=card, user=u) c.save() except ObjectDoesNotExist: u = User(id=id, name=name, subscribed=subscribed) u.save() c = Card(card_id=card, user=u) c.save() self.user_does_not_exist = '12345678' # user 2 is a user p = Permission(user=User.objects.get(pk=2), permission=1, tool=Tool.objects.get(pk=1), addedby=User.objects.get(pk=1)) p.save() # user 1 is a maintainer p = Permission(user=User.objects.get(pk=1), permission=2, tool=Tool.objects.get(pk=1), addedby=User.objects.get(pk=1)) p.save() # make the android tag a user # p = Permissions(user=User.objects.get(pk=8), permission=1, tool=Tool.objects.get(pk=1), addedby=User.objects.get(pk=1)) # p.save() # make the temp card a maintainer # p = Permissions(user=User.objects.get(pk=5), permission=2, tool=Tool.objects.get(pk=1), addedby=User.objects.get(pk=1)) # p.save() # make user 4 a maintainer p = Permission(user=User.objects.get(pk=4), permission=2, tool=Tool.objects.get(pk=1), addedby=User.objects.get(pk=1)) p.save()