Skip to content

Commit 1d40138

Browse files
committed
Add usage examples to README
1 parent 8ffc44f commit 1d40138

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,75 @@ $ pip install lanpartydb
2020
```
2121

2222

23+
## Usage
24+
25+
To serialize a party with only the required attributes to TOML:
26+
27+
```py
28+
from datetime import date
29+
30+
from lanpartydb.models import Party
31+
from lanpartydb.writing import serialize_party
32+
33+
party = Party(
34+
slug='megalan-2023',
35+
title='MegaLAN 2023',
36+
start_on=date(2023, 11, 17),
37+
end_on=date(2023, 11, 19),
38+
)
39+
40+
toml = serialize_party(party)
41+
42+
print(toml)
43+
```
44+
45+
And to serialize a party with all available attributes to a TOML file:
46+
47+
```py
48+
from datetime import date
49+
from decimal import Decimal
50+
from pathlib import Path
51+
52+
from lanpartydb.models import Links, Location, Party, Resource
53+
from lanpartydb.writing import serialize_party
54+
55+
party = Party(
56+
slug='superlan-2024',
57+
title='SuperLAN 2024',
58+
series_slug='superlan',
59+
organizer_entity='SuperLAN Association',
60+
start_on=date(2024, 5, 24),
61+
end_on=date(2024, 5, 26),
62+
seats=420,
63+
attendees=397,
64+
online=False,
65+
location=Location(
66+
name='City Hall',
67+
country_code='us',
68+
city='Los Angeles',
69+
zip_code='90099',
70+
street='123 North Hill Street',
71+
latitude=Decimal('34.06101057935884'),
72+
longitude=Decimal('-118.23974355902666'),
73+
),
74+
links=Links(
75+
website=Resource(
76+
url='https://www.superlan.example/',
77+
offline=False,
78+
),
79+
),
80+
)
81+
82+
toml = serialize_party(party)
83+
84+
path = Path('./superlan-2024.toml')
85+
path.write_text(toml)
86+
```
87+
88+
Take a look at the code (in `src/`) and the tests (in `tests/`) to learn
89+
more about the library's interface.
90+
91+
2392
## License
2493

2594
MIT

0 commit comments

Comments
 (0)