|  | @@ -24,18 +24,29 @@ def main():
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |      with open("scripts/aisamanra.json") as f:
 |  |      with open("scripts/aisamanra.json") as f:
 | 
												
													
														
															|  |          links = json.load(f)
 |  |          links = json.load(f)
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +    tags = {}
 | 
												
													
														
															|  |      for l in links:
 |  |      for l in links:
 | 
												
													
														
															|  | -        time = datetime.datetime.strptime(l["time"], "%Y-%m-%dT%H:%M:%SZ")
 |  | 
 | 
												
													
														
															|  | -        req = r.Link(
 |  | 
 | 
												
													
														
															|  | -            url=l["href"],
 |  | 
 | 
												
													
														
															|  | -            name=l["description"],
 |  | 
 | 
												
													
														
															|  | -            description=l["extended"],
 |  | 
 | 
												
													
														
															|  | -            private=l["shared"] == "no",
 |  | 
 | 
												
													
														
															|  | -            tags=l["tags"].split(),
 |  | 
 | 
												
													
														
															|  | -            created=time,
 |  | 
 | 
												
													
														
															|  | -        )
 |  | 
 | 
												
													
														
															|  | -        l = m.Link.from_request(u, req)
 |  | 
 | 
												
													
														
															|  | -        c.log(f"created link {l.url}")
 |  | 
 | 
												
													
														
															|  | 
 |  | +        for t in l["tags"].split():
 | 
												
													
														
															|  | 
 |  | +            if t in tags:
 | 
												
													
														
															|  | 
 |  | +                continue
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +            tags[t] = m.Tag.get_or_create_tag(u, t)
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +    with c.db.atomic():
 | 
												
													
														
															|  | 
 |  | +        for l in links:
 | 
												
													
														
															|  | 
 |  | +            time = datetime.datetime.strptime(l["time"], "%Y-%m-%dT%H:%M:%SZ")
 | 
												
													
														
															|  | 
 |  | +            ln = m.Link.create(
 | 
												
													
														
															|  | 
 |  | +                url=l["href"],
 | 
												
													
														
															|  | 
 |  | +                name=l["description"],
 | 
												
													
														
															|  | 
 |  | +                description=l["extended"],
 | 
												
													
														
															|  | 
 |  | +                private=l["shared"] == "no",
 | 
												
													
														
															|  | 
 |  | +                created=time,
 | 
												
													
														
															|  | 
 |  | +                user=u,
 | 
												
													
														
															|  | 
 |  | +            )
 | 
												
													
														
															|  | 
 |  | +            for t in l["tags"].split():
 | 
												
													
														
															|  | 
 |  | +                m.HasTag.create(link=ln, tag=tags[t])
 | 
												
													
														
															|  | 
 |  | +            c.log(f"created link {ln.url}")
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |  if __name__ == "__main__":
 |  |  if __name__ == "__main__":
 |