spelling
[plstackapi.git] / plstackapi / importer / plclassic / site_importer.py
1 from plstackapi.core.models import Site
2
3 class SiteImporter:
4
5     def __init__(self, api):
6         self.api = api
7         self.remote_sites = {}
8         self.local_sites = {}
9
10     def run(self):
11         db_sites = Site.objects.all()
12         for db_site in db_sites:
13             self.local_sites[db_site.login_base] = db_site
14         print "%s local sites" % len(db_sites)
15
16         sites = self.api.GetSites()
17         print "%s remote sites" % len(sites)
18         count = 0
19         for site in sites:
20             self.remote_sites[site['site_id']] = site 
21             if site['login_base'] not in self.local_sites:
22                 new_site = Site(name=site['name'],
23                                 login_base=site['login_base'],
24                                 site_url=site['url'],
25                                 enabled=site['enabled'],
26                                 longitude=site['longitude'],
27                                 latitude=site['latitude'],
28                                 is_public=site['is_public'],
29                                 abbreviated_name=site['abbreviated_name'])
30                 new_site.save()
31                 count += 1
32                 self.local_sites[new_site.login_base] = new_site
33         print "imported %s sites" % count