지금이 작업을 수행하는 데 적어도 2 시간을 소비했습니다. SO과 Google 그룹스에서 꽤 많이 다른 질문을 보았습니다. 그러나 그 답변 중 아무 것도 저에게 효과가없는 것 같습니다.AppEngine bulkloader가 key_name을 설정하여 항목을 업로드합니다.
질문 : 아래 CSV 파일의 데이터를 데이터 저장소에 일괄 업로드하여 CSV 파일에 key_name이 정의 된 엔티티를 만드는 방법 (아래의 추가 기능 사용과 동일한 결과) 위의 코드 make_key 단순히 도메인 소문자를하게하고 앞에 추가로 :
def add(domains):
"""
Add domains. This functions accepts a single domain string or a
list of domain strings and adds them to the database. The domain(s)
must be valid unicode strings (a ValueError is thrown if the domain
strings are not valid.
"""
if not isinstance(domains, list):
domains = [domains]
cleaned_domains = []
for domain in domains:
clean_domain_ = clean_domain(domain)
is_valid_domain(clean_domain_)
cleaned_domains.append(clean_domain_)
domains = cleaned_domains
db.put([RegisteredDomain(key_name=make_key(domain)) for domain in domains])
def get(domains):
"""
Get domains. This function accepts a single domain string or a list
of domain strings and queries the database for them. It returns a
dictionary containing the domain name and RegisteredDomain object or
None if the entity was not found.
"""
if not isinstance(domains, list):
domains = [domains]
entities = db.get([Key.from_path('RegisteredDomain', make_key(domain)) for domain in domains])
return dict(zip(domains, entities))
참고 :
여기class RegisteredDomain(db.Model):
"""
Domain object class. It has no fields because it's existence is
proof that it has been registered. Indivdual registered domains
can be found using keys.
"""
pass
내가 보통/삭제 도메인 등을 추가하는 방법은 다음과 같습니다
이
내 모델입니다 '디'.그래서 저기 있습니다. 이제 CSV 파일에서 일부 RegisteredDomain 항목을 업로드하는 데 미쳐 가고 있습니다. 여기에 CSV 파일 (첫 번째 문자 'D'를 참고로 인해 키 이름이 숫자로 시작되지 않을 수 있다는 사실이있다)이다 : 나는 수 없었다
key
dgoogle.com
dgoogle11.com
dfacebook.com
dcool.com
duuuuuuu.com
dsdsdsds.com
dffffooo.com
dgmail.com
bulkloader의 YAML을 자동 생성 파일은 앱 엔진이 아직 내 데이터 저장소 통계를 업데이트하지 않기 때문에 (1 일 플러스 몇 시간). 그래서이 (그리고 많은 유사한 순열은) 내가 (대부분 import_transform 비트 변경)과 함께 온 것입니다 : 나는 그것을 업로드하려고 어떤 이유로 지금
python_preamble:
- import: google.appengine.ext.bulkload.transform
- import: google.appengine.api.datastore
- import: google.appengine.ext.db
- import: utils
- import: bulk_helper
transformers:
- kind: RegisteredDomain
connector: csv
connector_options:
encoding: utf-8
property_map:
- property: __key__
external_name: key
export_transform: bulk_helper.key_to_reverse_str
import_template: transform.create_foreign_key('RegisteredDomain')
을 모두 잘가는 것을 말한다 및 X 개체가왔다 등을 전송하지만 데이터 저장소에서 아무 것도 업데이트되지 않습니다 (관리 콘솔에서 볼 수있는 것처럼).
appcfg.py upload_data --application=domain-sandwich --kind=RegisteredDomain --config_file=bulk.yaml --url=http://domain-sandwich.appspot.com/remote_api --filename=data.csv
그리고 마침내 내 데이터 저장소 뷰어 모습입니다 : 여기에 내가 업로드하는 방법입니다
참고 : I 작동 어떤 (dev에 서버와 애플리케이션 엔진에 모두이 일을하고있다 ..).
도움 주셔서 감사합니다.