Esempio n. 1
0
  plt.ylabel('Percentage gap Tory-Labour in 2015')
  plt.show()
  return 1

if args.marginals : 
  year = args.marginals[0]
  cutoff = args.marginals[1]

  if str(year) not in str(outputdatabase["elections"]) :
    print "You have asked for a non-existent year, exiting now"
    sys.exit(1)

  marginals(year,cutoff)
#
if args.marginals_between :
  party1 = nicepartynames(args.marginals_between[0])
  party2 = nicepartynames(args.marginals_between[1])
  year   = args.marginals_between[2]
  cutoff = args.marginals_between[3]

  if str(year) not in str(outputdatabase["elections"]) :
    print "You have asked for a non-existent year, exiting now"
    sys.exit(1)

  marginals_between(party1,party2,year,cutoff)
#
if args.gainbyparty :
  party = nicepartynames(args.gainbyparty[0])
  year   = int(args.gainbyparty[1])

  if year not in outputdatabase["elections"] :
Esempio n. 2
0
    constituency = ""
    winner = {"party": "", "vote": 0}
    runnerups = [{"party": "", "vote": 0}, {"party": "", "vote": 0}]
    electorate = 0
    turnout = 0.0
    for line in filetoread:
        if not foundconstituency:
            runnerup = 0
            # Find the start of a new constituency result
            # We look for Hold/Gain strings late in the line
            if line.find(" Hold") > 30 or line.find(" Gain") > 30:
                resultfirstline = line.split(",")
                if args.debug:
                    print resultfirstline
                constituency = resultfirstline[0].rstrip('"').lstrip('"')
                winner["party"] = nicepartynames(resultfirstline[3])
                winner["vote"] = int(resultfirstline[4])
                electorate = int(resultfirstline[6])
                turnout = float(resultfirstline[8].rstrip("%"))
                foundconstituency = True
            continue
        # If we got this far we are adding a new constituency result
        resultsecondline = line.split(",")
        if args.debug:
            print resultsecondline
        runnerups[runnerup]["party"] = nicepartynames(resultsecondline[3])
        runnerups[runnerup]["vote"] = int(resultsecondline[4])
        storeoneentry(outputdatabase, constituency, year, winner, runnerups, electorate, turnout)

        runnerup += 1
        if runnerup > 1: