def decode(key, value): if isinstance(value, get_dumpable_types()): return value if isinstance(value, (tuple, list)): return [decode(key, x) for x in value] if not isinstance(value, dict): return value if '__type' not in value: return dict([(k, decode(k, v)) for k, v in iteritems(value)]) _type = value['__type'] if _type == 'Pointer': value = copy.deepcopy(value) class_name = value['className'] pointer = leancloud.Object.create(class_name) if 'createdAt' in value: value.pop('__type') value.pop('className') pointer._update_data(value) else: pointer._update_data({'objectId': value['objectId']}) return pointer if _type == 'Object': value = copy.deepcopy(value) class_name = value['className'] value.pop('__type') value.pop('className') obj = leancloud.Object.create(class_name) obj._update_data(value) return obj if _type == 'Date': return arrow.get(iso8601.parse_date(value['iso'])).to('local').datetime if _type == 'GeoPoint': return leancloud.GeoPoint(latitude=value['latitude'], longitude=value['longitude']) if key == 'ACL': if isinstance(value, leancloud.ACL): return value return leancloud.ACL(value) if _type == 'Relation': relation = leancloud.Relation(None, key) relation.target_class_name = value['className'] return relation if _type == 'File': f = leancloud.File(value['name']) meta_data = value.get('metaData') if meta_data: f._metadata = meta_data f._url = value['url'] f.id = value['objectId'] return f
import leancloud import geocoder print("Connecting to server..") leancloud.init("Yf3MSyqMdVjhofKx5vflC4eF-MdYXbMMI", "n63Ne1Jj2bs17yGUPzSuYq7K") # myloc = geocoder.ip('me') # print(myloc.latlng) current_location = geocoder.ip('me').latlng pin = leancloud.Object.extend('Pinpoint') current = pin() current.set('Location', leancloud.GeoPoint(current_location[0], current_location[1])) current.save() print("Pinpoint complete!")
def decode(key, value): if isinstance(value, get_dumpable_types()): return value if isinstance(value, (tuple, list)): return [decode(key, x) for x in value] if not isinstance(value, dict): return value if key == "ACL": if isinstance(value, leancloud.ACL): return value return leancloud.ACL(value) if "__type" not in value: return dict([(k, decode(k, v)) for k, v in six.iteritems(value)]) _type = value["__type"] if _type == "Pointer": value = copy.deepcopy(value) class_name = value["className"] pointer = leancloud.Object.create(class_name) if "createdAt" in value: value.pop("__type") value.pop("className") pointer._update_data(value) else: pointer._update_data({"objectId": value["objectId"]}) return pointer if _type == "Object": value = copy.deepcopy(value) class_name = value["className"] value.pop("__type") value.pop("className") obj = leancloud.Object.create(class_name) obj._update_data(value) return obj if _type == "Date": return arrow.get(iso8601.parse_date(value["iso"])).to("local").datetime if _type == "GeoPoint": return leancloud.GeoPoint( latitude=value["latitude"], longitude=value["longitude"] ) if _type == "Relation": relation = leancloud.Relation(None, key) relation.target_class_name = value["className"] return relation if _type == "File": f = leancloud.File(value["name"]) meta_data = value.get("metaData") if meta_data: f._metadata = meta_data f._url = value["url"] f.id = value["objectId"] return f
from datetime import datetime import time import requests from random import choice leancloud.init("0ddsmQXAJt5gVLLE604DtE4U-gzGzoHsz", "XRGhgA5IwbqTWzosKRh3nzRY") Event = leancloud.Object.extend('Event') queryUser = leancloud.Query('_User') queryConv = leancloud.Query('_Conversation') Conversation = leancloud.Object.extend('_Conversation') flag = "1" for i in xrange(2): point = leancloud.GeoPoint(39.9, 116.4) queryUser.exists('username') users = queryUser.find() creator = users[choice(range(0, len(users)))] name = flag + "test test test " + str(i) conversation = Conversation() conversation.set('name', name) conversation.set('m', [creator.get('username')]) conversation.save() queryConv.equal_to('name', name) conversations = queryConv.find() event = Event() event.set('name', name) event.set('maximumAttendingPeople', 20) event.set('remainingSeats', 1) event.set('minimumAttendingPeople', 20)