im writing program takes school grades , makes them desktop background when program parses grades site returns them 1
code retrieves grades school grade site:
for cell in driver.find_elements_by_css_selector(".grid tr a[href$='fg=s2']"): print cell.text cell.text comes as
-- b 84 -- a- 90 -- c+ 79 -- 95 -- b 82 -- b 81 but need input image desktop bg
font = imagefont.load_default() img = image.open('bg.bmp') draw = imagedraw.draw(img) = datetime.datetime.now() draw.text((650, 450),' current grades' ) draw.text((650, 500), 'period 1: geography -----------------------------')#first grade draw.text((650, 550), 'period 2: francais-------------------------------')#second grade draw.text((650, 600), 'period 3: science--------------------------------')#third grade draw.text((650, 650), 'period 4: p.e------------------------------------')#fourth grade draw.text((650, 700), 'period 5: algebra 9------------------------------')#fifth grade draw.text((650, 750), 'period 6: la-------------------------------------')sixth grade draw.text((650, 800), 'last updated: {0}'.format(now)) draw = imagedraw.draw(img) draw = imagedraw.draw(img) img.save('mod_bg.bmp') when grades returned need them put each class
if info needed ask thanks
if you're having difficulty getting data out of string cell.text might want following.
i've put data string start have self-contained test:
grades = """-- b 84 -- a- 90 -- c+ 79 -- 95 -- b 82 -- b 81""" gradeslist = grades.split('\n') lettergrade = gradeslist[1::3] pctgrade = [int(x) x in gradeslist[2::3]] in range(len(lettergrade)): print ("%s\t%d" % (lettergrade[i],pctgrade[i])) ... , i'm printing result console rather putting image, @tankorsmash has shown how latter part.
the output program is:
b 84 a- 90 c+ 79 95 b 82 b 81 for more information on splitting multi-line strings, see here. more information on slicing lists 3 limits, see here.
Comments
Post a Comment