Python increment pulling from an array in a loop -
i trying create would
- read file
- separate ever thing array
- use first string in array , something
- after done go second array , something
- keep repeating process until array done.
so far have
users = open('users.txt', "r") userl = users.read().splitlines()
what want open text file, separated 1 line per string, have python part put array, first string , set variable. there variable used in url xbox.com.
after checks have json read page , see if gamertag list have being used, if being used go array , go second string , check. needs constant loop of checking gamertags. if find gamertag in array (from text file) isn't used, save text file entitled "available gametags" , keep moving on.
what want (requested in comments)
- open program
- have read text file of usernames have created
- have program test each program @ end of gamertag viewer link xbox
- json read page , if contains info name taken goes list , uses next gamertag on page.
- keeps doing this
- logs gamertags worked , saves text file.
- exits
the problem in doing don't know how go file , access line after 1 tested , continue pattern until file read.
use loop:
with open("users.txt") f: line in f: # whatever line
for example, achieve goal here, might this:
# import our required modules import json import urllib2 # declare initial variables input_file = "users.txt" output_file = "available_tags.txt" available_tags = [] # empty list hold our available gamertags # open file open(input_file) input_f: # loop through each line line in input_f: # strip new line character line tag = line.strip() # set our url , open connection api url = "http://360api.chary.us/?gamertag=%s" % tag u = urllib2.urlopen(url) # load returned data json object data = json.loads(u.read()) # check if gamertag available if not data['gamertagexists']: # print , add our list of available tags if print "tag %s available." % tag available_tags.append(tag) else: print "tag %s not available." % tag #otherwise # check have @ least 1 valid tag store if len(available_tags) > 0: # open our output file open(output_file, "w") output_f: # loop through our available tags tag in available_tags: # write each 1 file output_f.write("%s\n" % tag) else: print "no valid tags written output file."
Comments
Post a Comment