-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlean_cloud.py
60 lines (45 loc) · 1.26 KB
/
lean_cloud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import leancloud
import logging
logging.basicConfig(format='%(asctime)s %(levelname)s : %(message)s', level=logging.INFO, datefmt='%m-%d %H:%M:%S')
leancloud.init("")
HitoItem = leancloud.Object.extend('HitoItem')
query = leancloud.Query(HitoItem)
def except_decorative(func):
def decorator(*args, **keyargs):
try:
return func(*args, **keyargs)
except Exception as e:
logging.error(f'handle {func.__name__} error: {e}')
return decorator
# def create_int():
# obj = HitoItem()
# obj.set('cid', '19830330')
# obj.set('update', True)
# obj.save()
@except_decorative
def find_by_cid(cid):
a = query.equal_to('cid', cid).find()
if len(a) > 0:
return a[0]
def save_val(cid, count, name):
obj = HitoItem()
obj.set('cid', cid)
obj.set('count', count)
obj.set('name', name)
obj.save()
def update_val(cid, count):
item = find_by_cid(cid)
if not item:
return
item.set('count', count)
where = HitoItem.query.equal_to('cid', cid)
item.save(where=where)
def update_update(val):
cql = 'update HitoItem set update = ? where objectId = ?'
result = leancloud.Query.do_cloud_query(cql, val, '5c305f460b61600067656668')
if __name__ == '__main__':
# create_int()
# save_val('1', 123)
update_update(False)
# update_val('1231',213213)
# a = find_by_cid('123')