示例#1
0
 def __init__(self, clubnumber, clubname, area, division, district, suspenddate):
     self.name = clubname
     self.clubnumber = stringify(clubnumber)
     self.area = stringify(area)
     self.division = division
     self.district = stringify(district)
     self.suspenddate = suspenddate
     # Pre-set information in case it doesn't get filled in later (if the club only
     #    exists part of the year, for example, or if there is no charter info)
     self.charterdate = ''
     if (self.division == '0D') or (self.area == '0A'):
         # Fully unassign an unassigned club
         self.area = '0A'
         self.division = '0D'
示例#2
0
文件: allstats.py 项目: d4tm/tmstats
 def __init__(self, clubnumber, clubname, area, division, district, suspenddate):
     self.name = clubname
     self.clubnumber = stringify(clubnumber)
     self.area = stringify(area)
     self.division = division
     self.district = stringify(district)
     self.suspenddate = suspenddate
     # Pre-set information in case it doesn't get filled in later (if the club only
     #    exists part of the year, for example, or if there is no charter info)
     self.charterdate = ''
     if (self.division == '0D') or (self.area == '0A'):
         # Fully unassign an unassigned club
         self.area = '0A'
         self.division = '0D'
示例#3
0
文件: latest.py 项目: d4tm/tmstats
def getlatest(table, conn):
    curs = conn.cursor()
    # The MySQLdb library doesn't allow interpolating the table name, so we do
    # it via normal Python.
    statement = 'select t.monthstart, l.latest FROM %s t INNER JOIN (select max(loadedfor) as latest FROM loaded WHERE tablename="%s") l ON t.asof = l.latest GROUP BY t.monthstart, l.latest' % (table, table)
    try:
        curs.execute(statement)
        ans = curs.fetchone()
        ans = [tmutil.stringify(x) for x in ans]
    except (MySQLdb.Error, TypeError), e:
        sys.stderr.write(repr(e))
        ans = ('', '')
示例#4
0
文件: latest.py 项目: ghoshen/tmstats
def getlatest(table, conn):
    curs = conn.cursor()
    # The MySQLdb library doesn't allow interpolating the table name, so we do
    # it via normal Python.
    district = tmparms.tmparms().district
    statement = 'select t.monthstart, l.latest FROM %s t INNER JOIN (select max(loadedfor) as latest FROM loaded WHERE tablename="%s") l ON t.asof = l.latest WHERE district = "%s" GROUP BY t.monthstart, l.latest' % (table, table, district)
    try:
        curs.execute(statement)
        ans = curs.fetchone()
        if ans:
            ans = [tmutil.stringify(x) for x in ans]
        else:
            ans = ('', '')
    except (MySQLdb.Error, TypeError) as e:
        sys.stderr.write(repr(e))
        ans = ('', '')
    return ans
示例#5
0
    parms.add_argument('--district', type=int)

    # Do global setup
    globals.setup(parms)
    conn = globals.conn
    curs = globals.curs

    # Get the existing awards (significant parts only) so we don't create duplicates.  We can't
    #   let the datbase do it because we don't have a valid unique key - a person can earn
    #   identical awards for the same club on the same date.
    existing = set()
    curs.execute("SELECT membername, clubnumber, award, awarddate FROM awards")
    for (membername, clubnumber, award, awarddate) in curs.fetchall():
        existing.add(
            makekey(membername, clubnumber, award,
                    tmutil.stringify(awarddate)))

    # Get the data from Toastmasters
    url = "http://reports.toastmasters.org/reports/dprReports.cfm?r=3&d=%d&s=Club&sortOrder=0" % parms.district
    data = requests.get(url).text
    # Parse it
    soup = BeautifulSoup(data, 'html.parser')

    awards = []
    # We want siblings of the first table row of class "content"
    starter = soup.find('tr', class_='content')
    line = starter.find_next_sibling("tr")
    while line:
        candidate = [s.strip() for s in line.stripped_strings]
        line = line.find_next_sibling("tr")
示例#6
0
    parms.parser.add_argument("--finaldate", dest='finaldate', type=str, default='4/15')
    parms.parser.add_argument('--outfile', default='presidentsclub.txt')
    parms.parser.add_argument('--earning', default='$101 in District Credit')
    parms.parser.add_argument('--requiremembership', action='store_true', help='Specify to require that clubs meet membership goals to qualify.')

    # Do global setup
    globals.setup(parms)
    curs = globals.curs
    conn = globals.conn
    
    
    # Your main program begins here.
    
    # We want data from either the final date or the latest available, whichever is earlier
    curs.execute("SELECT MAX(asof) FROM clubperf")
    latest = stringify(curs.fetchone()[0])
    parms.finaldate = cleandate(parms.finaldate)
    targetdate = min(latest, parms.finaldate)
    final = (targetdate == parms.finaldate)
    status = "final" if final else "updated daily"
    
    # Open the output file
    outfile = open(parms.outfile, 'w')

    winners = []
    
    if parms.requiremembership:
    
        # See if WHQ has posted any President's Distinguished Clubs; if so,
        #   use their information.  If not, calculate on our own.
示例#7
0
    curs = myglobals.curs

    # Let's see if we're supposed to run today.
    if parms.runon:
        weekday = datetime.datetime.today().strftime('%A')
        run = [True for w in parms.runon if weekday.startswith(w)]  # Note:  T means Tuesday OR Thursday; S is Saturday OR Sunday
        if not run:
            #sys.stderr.write('Not running because today is %s but --runon=%s was specified\n' % (weekday, ' '.join(parms.runon)))
            sys.exit(0)  # Not running is a normal exit.
    
    # OK, we are running.  Figure out the dates to use.
    if parms.todate:
        cleanedtodate = cleandate(parms.todate, usetmyear=False)
        # Go forward to the first date with data on or after the date specified
        curs.execute("SELECT MIN(loadedfor) FROM loaded where tablename = 'clubs' AND loadedfor >= %s", (cleanedtodate,))
        todate = stringify(curs.fetchone()[0])
        if todate is None:
            todate = cleanedtodate
    else:
        # We want the last date in the database
        curs.execute("SELECT MAX(loadedfor) FROM loaded WHERE tablename = 'clubs'")
        todate = stringify(curs.fetchone()[0])

    if parms.fromdate:
        fromdate = cleandate(parms.fromdate,usetmyear=False)
        # Go backwards to the last date with data on or before the date specified 
        curs.execute("SELECT MAX(loadedfor) FROM loaded where tablename = 'clubs' AND loadedfor <= %s", (fromdate,))
        fromdate = stringify(curs.fetchone()[0])
    else:
        # We want the most recent date with data before the todate
        curs.execute("SELECT MAX(loadedfor) FROM loaded WHERE tablename = 'clubs' AND loadedfor < %s", ((todate,)))
示例#8
0
    parms.add_argument('--quiet', '-q', action='count', default=0)
    parms.add_argument('--district', type=int)
    
    # Do global setup
    globals.setup(parms)
    conn = globals.conn
    curs = globals.curs

    
    # Get the existing awards (significant parts only) so we don't create duplicates.  We can't 
    #   let the datbase do it because we don't have a valid unique key - a person can earn 
    #   identical awards for the same club on the same date.
    existing = set()
    curs.execute("SELECT membername, clubnumber, award, awarddate FROM awards")
    for (membername, clubnumber, award, awarddate) in curs.fetchall():
        existing.add(makekey(membername, clubnumber, award, tmutil.stringify(awarddate)))
        
    
    # Get the data from Toastmasters
    url = "http://reports.toastmasters.org/reports/dprReports.cfm?r=3&d=%d&s=Club&sortOrder=0" % parms.district
    data = requests.get(url).text
    # Parse it
    soup = BeautifulSoup(data, 'html.parser')

    awards = []
    # We want siblings of the first table row of class "content"
    starter = soup.find('tr', class_='content')
    line = starter.find_next_sibling("tr")
    while line:
        candidate = [s.strip() for s in line.stripped_strings]
        line = line.find_next_sibling("tr")
示例#9
0
    parms.parser.add_argument('--earning', default='$101 in District Credit')
    parms.parser.add_argument(
        '--requiremembership',
        action='store_true',
        help='Specify to require that clubs meet membership goals to qualify.')

    # Do global setup
    myglobals.setup(parms)
    curs = myglobals.curs
    conn = myglobals.conn

    # Your main program begins here.

    # We want data from either the final date or the latest available, whichever is earlier
    curs.execute("SELECT MAX(asof) FROM clubperf")
    latest = stringify(curs.fetchone()[0])
    parms.finaldate = cleandate(parms.finaldate)
    targetdate = min(latest, parms.finaldate)
    final = (targetdate == parms.finaldate)
    status = "final" if final else "updated daily"

    # Open the output file
    outfile = open(parms.outfile, 'w')

    winners = []

    if parms.requiremembership:

        # See if WHQ has posted any President's Distinguished Clubs; if so,
        #   use their information.  If not, calculate on our own.
示例#10
0
    curs = globals.curs

    # Let's see if we're supposed to run today.
    if parms.runon:
        weekday = datetime.datetime.today().strftime('%A')
        run = [True for w in parms.runon if weekday.startswith(w)]  # Note:  T means Tuesday OR Thursday; S is Saturday OR Sunday
        if not run:
            #sys.stderr.write('Not running because today is %s but --runon=%s was specified\n' % (weekday, ' '.join(parms.runon)))
            sys.exit(0)  # Not running is a normal exit.
    
    # OK, we are running.  Figure out the dates to use.
    if parms.todate:
        cleanedtodate = cleandate(parms.todate, usetmyear=False)
        # Go forward to the first date with data on or after the date specified
        curs.execute("SELECT MIN(loadedfor) FROM loaded where tablename = 'clubs' AND loadedfor >= %s", (cleanedtodate,))
        todate = stringify(curs.fetchone()[0])
        if todate is None:
            todate = cleanedtodate
    else:
        # We want the last date in the database
        curs.execute("SELECT MAX(loadedfor) FROM loaded WHERE tablename = 'clubs'")
        todate = stringify(curs.fetchone()[0])

    if parms.fromdate:
        fromdate = cleandate(parms.fromdate,usetmyear=False)
        # Go backwards to the last date with data on or before the date specified 
        curs.execute("SELECT MAX(loadedfor) FROM loaded where tablename = 'clubs' AND loadedfor <= %s", (fromdate,))
        fromdate = stringify(curs.fetchone()[0])
    else:
        # We want the most recent date with data before the todate
        curs.execute("SELECT MAX(loadedfor) FROM loaded WHERE tablename = 'clubs' AND loadedfor < %s", ((todate,)))