Added memberlist.py, a tool to JSON dump the member list
It has simplejson as a requirement. Python >2.6 ships it by default IIRC. There is a version of simplejson compatible with Python >2.4. You also need to have MySQL set up via ~/.my.cnf as the file referenced in the imports states.
This commit is contained in:
		
							parent
							
								
									85ede4c945
								
							
						
					
					
						commit
						4accb41992
					
				
					 1 changed files with 40 additions and 0 deletions
				
			
		
							
								
								
									
										40
									
								
								bin/memberlist.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								bin/memberlist.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,40 @@ | ||||||
|  | #!/usr/bin/env python | ||||||
|  | '''Prints the current member list as JSON''' | ||||||
|  | 
 | ||||||
|  | try: | ||||||
|  |     import json | ||||||
|  | except ImportError: | ||||||
|  |     import simplejson as json | ||||||
|  | 
 | ||||||
|  | from get_renewees import execute_query, Member | ||||||
|  | 
 | ||||||
|  | query = ("SET NAMES 'utf8'; " | ||||||
|  |          "SELECT CONCAT(firstname, ';', lastname, ';', email, ';', " | ||||||
|  |          "              last_renewed_on) " | ||||||
|  |          " FROM foundationmembers" | ||||||
|  |          " WHERE DATE_SUB(CURDATE(), INTERVAL 2 YEAR) <= last_renewed_on" | ||||||
|  |          " ORDER BY lastname, firstname") | ||||||
|  |        | ||||||
|  | 
 | ||||||
|  | def get_current_electorate(): | ||||||
|  |     infile = execute_query(query) | ||||||
|  |     memberlist = [Member.from_csv(line.strip()) for line in infile] | ||||||
|  | 
 | ||||||
|  |     return memberlist | ||||||
|  |              | ||||||
|  | 
 | ||||||
|  | def get_json_memberlist(): | ||||||
|  |     members = get_current_electorate() | ||||||
|  |     objects = [ | ||||||
|  |         {'firstname': o.firstname, | ||||||
|  |          'lastname': o.lastname, | ||||||
|  |          'email': o.email, | ||||||
|  |          'last_renewed_on': o.token_or_last_renewed_on, | ||||||
|  |         } | ||||||
|  |         for o in members] | ||||||
|  |      | ||||||
|  |     j = json.dumps(objects, indent=4) | ||||||
|  |     return j | ||||||
|  | 
 | ||||||
|  | if __name__ == '__main__': | ||||||
|  |     print get_json_memberlist() | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Tobias Mueller (ideabox)
						Tobias Mueller (ideabox)