Skip to content

Commit

Permalink
Adding CSV example and system overrides for env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mzkrasner committed Oct 10, 2024
1 parent 988aff8 commit a347400
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ceramicsdk/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
requests==2.32.2
requests==2.31.0
python-dateutil==2.8.2
pytz==2023.3
jsonpatch==1.33
cryptography==43.0.1
jwcrypto==1.5.0
multiformats==0.3.1
dag-cbor==0.3.2
dag-cbor==0.3.3
base58==2.1.1
web3==7.2.0
cbor2==5.6.4
Expand Down
4 changes: 2 additions & 2 deletions ceramicsdk/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
],
python_requires=">=3.7",
install_requires=[
"requests==2.32.2",
"requests==2.31.0",
"python-dateutil==2.8.2",
"pytz==2023.3",
"jsonpatch==1.33",
"cryptography==43.0.1",
"jwcrypto==1.5.0",
"multiformats==0.3.1",
"dag-cbor==0.3.2",
"dag-cbor==0.3.3",
"base58==2.1.1",
"web3==7.2.0",
"cbor2==5.6.4",
Expand Down
56 changes: 56 additions & 0 deletions csv-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
from dotenv import load_dotenv
from ceramicsdk import OrbisDB
import json
import csv
from typing import List, Dict


load_dotenv(dotenv_path='.env',override=True)

ENV_ID = os.getenv("ENV_ID")
TABLE_ID = os.getenv("TABLE_ID")
CONTEXT_ID = os.getenv("CONTEXT_ID")
CERAMIC_ENDPOINT = os.getenv("CERAMIC_ENDPOINT")
ORBIS_ENDPOINT = os.getenv("ORBIS_ENDPOINT")

# filename
filename = 'sample.csv'


def get():
seed = os.urandom(32).hex()
print(CERAMIC_ENDPOINT)
orbis = OrbisDB(c_endpoint=CERAMIC_ENDPOINT,
o_endpoint=ORBIS_ENDPOINT,
context_stream=CONTEXT_ID,
table_stream=TABLE_ID,
controller_private_key=seed)
print(orbis.ceramic_client.did.id)
return json.dumps(orbis.ceramic_client.did.id)


def create_document():
seed = os.urandom(32).hex()
orbis = OrbisDB(c_endpoint=CERAMIC_ENDPOINT,
o_endpoint=ORBIS_ENDPOINT,
context_stream=CONTEXT_ID,
table_stream=TABLE_ID,
controller_private_key=seed)
data = []
with open(filename, mode='r') as file:
csvFile = csv.DictReader(file)
for lines in csvFile:
data.append(lines)

for i in range(len(data)):
line = data[i]
# ensure line.customer_user_id is an integer
line['customer_user_id'] = int(line['customer_user_id'])
doc = orbis.add_row(line)
print(doc)

# Return stringified stream_id
return json.dumps(doc)

create_document()
17 changes: 17 additions & 0 deletions sample.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
page,address,customer_user_id,timestamp
"/home","0x8071f6F971B438f7c0EA72C950430EE7655faBCe",3,"2024-09-25T15:06:14.957719+00:00"
"/about","0x92F78b3F2dDF4B7585B8b207654f7EcEadD4Fe8E",8,"2024-09-25T16:14:22.364819+00:00"
"/contact","0xA1D342F29bBC9e8DeD13Fc2671A3D2bFd4F8eE3E",12,"2024-09-25T17:01:53.589671+00:00"
"/products","0xB5C4F9182aAAE203F3cF92CcDc3D7e243cC56Ac1",5,"2024-09-25T17:43:06.127543+00:00"
"/cart","0x29A02f67b2d8F6D1937a5fDfE8f7F57e75F7Cf2a",9,"2024-09-25T18:29:32.987345+00:00"
"/checkout","0xDf1B8b9bD31f72314C92D4EbCfD8a8cE847E02d6",11,"2024-09-25T19:02:41.235312+00:00"
"/profile","0x714cDa82C6E2E7f28f49f3424cAcB2Dc2dC8cF3C",6,"2024-09-25T19:45:13.556789+00:00"
"/home","0x3207A8D2C8c5b8Dce3dE2Fbd3B8A29cD1a5E1B4E",10,"2024-09-25T20:33:17.164512+00:00"
"/login","0x9c5b8D4fBcDaE34F9dA91Eb2cAfB7E4eD1a78E8D",7,"2024-09-25T21:06:51.897613+00:00"
"/products","0x3F1A4D6d8dD3c6cB92F5b7bB2a6eE42cF9D9B7B2",2,"2024-09-25T21:59:39.474829+00:00"
"/settings","0x7bE7C7A8F4e9d8cC9b0fA88E3D5C8F3fFaA3F3d3",13,"2024-09-25T22:12:14.098654+00:00"
"/home","0x1c2d3e6F456d8c1B9bA2D4E7c5F9A8D7C6D7c8F9",14,"2024-09-26T09:25:48.573245+00:00"
"/about","0x4a1d5B7C2c8F2eF8eD1fC3eF8cA4E7dD7A4F7e8F",15,"2024-09-26T10:34:12.986531+00:00"
"/profile","0x5C9e7D4bD6F9C8cB9eA2B5D7e5A3F1eB1A7D4B3C",4,"2024-09-26T11:48:27.685934+00:00"
"/contact","0x1b7f3A4eE8cA7bD4C9bE2A4D5A9F4B2cC1e8d7A3",16,"2024-09-26T12:59:19.462876+00:00"
"/checkout","0x6b1c7A4eB8dD7C2dA8fA3F5C7D8e9E1B3d9E4F3A",1,"2024-09-26T13:21:34.873425+00:00"
2 changes: 1 addition & 1 deletion server-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

app = Flask(__name__)

load_dotenv()
load_dotenv(dotenv_path='.env',override=True)

ENV_ID = os.getenv("ENV_ID")
TABLE_ID = os.getenv("TABLE_ID")
Expand Down

0 comments on commit a347400

Please sign in to comment.