json profile export
This commit is contained in:
		
							parent
							
								
									ae6650c775
								
							
						
					
					
						commit
						0b8b5ce498
					
				
							
								
								
									
										27
									
								
								microblog.py
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								microblog.py
									
									
									
									
									
								
							| @ -160,8 +160,7 @@ def parse_txt(filename): | ||||
|                 state = 0  | ||||
|     return posts | ||||
| 
 | ||||
| def get_posts(filename, config): | ||||
|     posts = parse_txt(filename) | ||||
| def get_posts(posts, config): | ||||
|     taginfos = [] | ||||
|     tagcloud = dict() # (tag, count) | ||||
|     tagged   = dict() # (tag, index of message) | ||||
| @ -347,6 +346,22 @@ if __name__ == "__main__": | ||||
|             s = None | ||||
|         return s | ||||
| 
 | ||||
|     import json | ||||
|     # generate json basd on profile  | ||||
|     def export_profile(post_count, last_update, config): | ||||
|         if "alias" not in config["profile"] \ | ||||
|         or "url" not in config["profile"]: | ||||
|             print("Warning: no profile exported", file=sys.stderr) | ||||
|             return | ||||
|         profile = { | ||||
|             "username" : config["profile"]["alias"], | ||||
|             "url": config["profile"]["url"], | ||||
|             "last-updated": last_update, | ||||
|             "post-count" : post_count | ||||
|         } | ||||
|         with open(config["file_output"], 'w') as f: | ||||
|             print(json.dumps(profile), file=f) | ||||
| 
 | ||||
|     def main(): | ||||
|         tpl, content = get_args() | ||||
|         cfg = load_settings() | ||||
| @ -359,7 +374,13 @@ if __name__ == "__main__": | ||||
|         if "page" not in cfg: | ||||
|             print("exit: table 'page' absent in settings.toml", file=sys.stderr) | ||||
|             return | ||||
|         tl, tc, tg = get_posts(content, cfg["post"]) | ||||
|         p = parse_txt(content) | ||||
|         if "syndication" in cfg: | ||||
|             if cfg["syndication"]["enabled"] == True: | ||||
|                 export_profile( | ||||
|                     len(p), p[0].get_epoch_time(), cfg["syndication"] | ||||
|                 ) | ||||
|         tl, tc, tg = get_posts(p, cfg["post"]) | ||||
|         if tl == []: | ||||
|             return | ||||
|         # main timeline | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user