ansent commited on
Commit
c0b2853
1 Parent(s): 154e521

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -35
app.py CHANGED
@@ -1,41 +1,16 @@
1
- import os
2
-
3
  from pyairtable import Table
4
- from pyairtable.formulas import match
5
- from dotenv import load_dotenv, find_dotenv
6
- load_dotenv(find_dotenv())
7
-
8
- AIRTABLE_TOKEN = os.getenv('patmeLtGxrVz8HN1C.699482b9f0c5ea37997a38ff8964f71726630d4859f3eef542aaff9f097bba86')
9
- BASE_ID = os.getenv('app4WdpCpbne8JVJU')
10
- table_name='users'
11
 
12
- def create_record(table_name: str, record: dict) -> dict:
13
- table = Table(AIRTABLE_TOKEN, BASE_ID, table_name)
14
- result = table.create(record)
15
- return result
16
 
17
- def get_record(table_name: str, filter: dict) -> dict:
18
- formula = match(filter)
19
- table = Table(AIRTABLE_TOKEN, BASE_ID, table_name)
20
- result = table.all(formula=formula)
21
- return result
22
 
23
- def update_record(table_name: str, filter: dict, update: dict) -> dict:
24
- formula = match(filter)
25
- table = Table(AIRTABLE_TOKEN, BASE_ID, table_name)
26
- record = table.all(formula=formula)
27
- if len(record) > 0:
28
- id = record[0]['id']
29
- result = table.update(id, update)
30
- return result
31
- else:
32
- return []
33
-
34
- result = create_record('users', {'username': 'ansentase'})
35
- print(result)
36
 
37
- # result = get_record('users', {'username': 'x'})
38
- # print(result)
 
39
 
40
- # result = update_record('users', {'username': 'x'}, {'username': 'xyz123'})
41
- # print(result)
 
 
 
1
  from pyairtable import Table
 
 
 
 
 
 
 
2
 
3
+ # Set up the connection to our Airtable table
4
+ BASE_ID = "app4WdpCpbne8JVJU"
5
+ API_KEY="patmeLtGxrVz8HN1C.699482b9f0c5ea37997a38ff8964f71726630d4859f3eef542aaff9f097bba86"
6
+ TABLE_NAME="pytable"
7
 
8
+ table = Table(API_KEY, BASE_ID, TABLE_NAME)
 
 
 
 
9
 
10
+ same="ansentase"
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ add_this={
13
+ "Name":same
14
+ }
15
 
16
+ table.create(add_this)