コード例 #1
0
def import_site_export(export_path, remote_api_host,
                       app_id, batch_size, store_all):
  # log in, then use the pfif parser to parse the export file. Use the importer
  # methods to convert the dicts to entities then add them as in import.py, but
  # less strict, to ensure that all exported data is available.
  remote_api.init(app_id, remote_api_host)
  logging.info('%s: importing exported records from %s',
               remote_api_host, export_path)
  if not export_path.endswith('.zip'):
    export_fd = open(export_path)
  else:
    export_fd = open_file_inside_zip(export_path)
  persons, notes = pfif.parse_file(export_fd)
  logging.info('loaded %d persons, %d notes', len(persons), len(notes))
  if not store_all:
    persons = [d for d in persons if
               not importer.is_local_domain(d.get('person_record_id', ''),
                                            'person')]
    notes = [d for d in notes if
             not importer.is_local_domain(d.get('note_record_id', ''),
                                          'note')]
    logging.info('... down to %d persons, %d notes after excluding %s records',
                 len(persons), len(notes), HOME_DOMAIN)
  logging.info('... adding persons')
  add_entities(persons, create_person, batch_size, 'person', store_all)
  logging.info('... adding notes')
  add_entities(notes, create_note, batch_size, 'note', store_all)
コード例 #2
0
ファイル: import.py プロジェクト: jgeewax/googlepersonfinder
import csv
import importer
import sys

SHOW_ERRORS = 5

def import_from_file(host, kind, converter, filename):
  print '%s: importing %s records from %s' % (host, kind, filename)
  written, skipped, total = importer.import_records(
      source_domain, converter,
      importer.utf8_decoder(csv.DictReader(open(filename))))
  for error, record in skipped[:SHOW_ERRORS]:
    print '  - %s: %r' % (error, record)
  if len(skipped) > SHOW_ERRORS:
    print '  (more errors not shown)'

  print 'wrote %d of %d (skipped %d with errors)' % (
      written, total, len(skipped))

if __name__ == '__main__':
  if len(sys.argv) < 6:
    raise SystemExit(
        'Usage: %s app_id host source_domain person.csv note.csv' % sys.argv[0])
  app_id, host, source_domain, person_file, note_file = sys.argv[1:]
  host = remote_api.init(app_id, host)
  if person_file:
    import_from_file(host, 'Person', importer.create_person, person_file)
  if note_file:
    import_from_file(host, 'Note', importer.create_note, note_file)
コード例 #3
0
ファイル: console.py プロジェクト: jgeewax/googlepersonfinder
#!/usr/bin/python2.5
# Copyright 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Unix command-line utility: interactive administration console."""

import code
import remote_api
import sys
from model import *

if __name__ == '__main__':
  if len(sys.argv) < 2:
    raise SystemExit('Usage: %s app_id [host]' % sys.argv[0])
  remote_api.init(*sys.argv[1:])
  code.interact('', None, locals())