Skip to content

Commit

Permalink
Use time in the UTC for the value of createdAt
Browse files Browse the repository at this point in the history
  • Loading branch information
mnogu committed May 10, 2023
1 parent 6ad2b42 commit db462d5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ $ python3
You can also post with `com.atproto.repo.create_record()`:
```python
from datetime import datetime
from datetime import timezone
from chitose import BskyAgent
from chitose.app.bsky.feed.post import Post

agent = BskyAgent(service='https://example.com')
agent.login(identifier='alice@mail.com', password='hunter2')

record = Post(text='Hello, world!', created_at=datetime.now().isoformat())
record = Post(text='Hello, world!',
created_at=datetime.now(timezone.utc).isoformat())
agent.com.atproto.repo.create_record(
repo=alice.did, collection='app.bsky.feed.post', record=record)
```
Expand Down
9 changes: 5 additions & 4 deletions chitose/agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations
from datetime import datetime
from datetime import timezone
import typing
import json

Expand Down Expand Up @@ -120,7 +121,7 @@ def like(self, uri: str, cid: str) -> bytes:

subject = StrongRef(uri=uri, cid=cid)
record = Like(subject=subject,
created_at=datetime.now().isoformat())
created_at=datetime.now(timezone.utc).isoformat())

return self.com.atproto.repo.create_record(
repo=self.session['did'],
Expand All @@ -143,7 +144,7 @@ def repost(self, uri: str, cid: str) -> bytes:

subject = StrongRef(uri=uri, cid=cid)
record = Repost(subject=subject,
created_at=datetime.now().isoformat())
created_at=datetime.now(timezone.utc).isoformat())

return self.com.atproto.repo.create_record(
repo=self.session['did'],
Expand All @@ -165,7 +166,7 @@ def follow(self, subject_did: str) -> bytes:
raise Exception('Not logged in')

record = Follow(subject=subject_did,
created_at=datetime.now().isoformat())
created_at=datetime.now(timezone.utc).isoformat())

return self.com.atproto.repo.create_record(
repo=self.session['did'],
Expand All @@ -190,7 +191,7 @@ def unmute_actor(self, actor: str) -> bytes:

def update_seen_notifications(self, seen_at: typing.Optional[str]) -> bytes:
if seen_at is None:
seen_at = datetime.now().isoformat()
seen_at = datetime.now(timezone.utc).isoformat()

return self.app.bsky.notification.update_seen(seen_at=seen_at)

Expand Down
5 changes: 4 additions & 1 deletion examples/post.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from datetime import datetime
from datetime import timezone

from chitose import BskyAgent
from chitose.app.bsky.feed.post import Post

Expand All @@ -8,7 +10,8 @@ def main():
agent = BskyAgent(service='https://bsky.social')
agent.login(identifier='YOUR_USERNAME', password='YOUR_PASSWORD')

record = Post(text='Hello, world!', created_at=datetime.now().isoformat())
record = Post(text='Hello, world!',
created_at=datetime.now(timezone.utc).isoformat())
agent.com.atproto.repo.create_record(
repo='YOUR_DID', collection='app.bsky.feed.post', record=record)

Expand Down
3 changes: 2 additions & 1 deletion examples/post_with_image.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
from datetime import timezone
import json

from chitose import BskyAgent
Expand Down Expand Up @@ -26,7 +27,7 @@ def main():
images = Images(images=[image])

record = Post(text='post with an image test',
created_at=datetime.now().isoformat(), embed=images)
created_at=datetime.now(timezone.utc).isoformat(), embed=images)
agent.com.atproto.repo.create_record(
repo='YOUR_DID', collection='app.bsky.feed.post', record=record)

Expand Down
5 changes: 4 additions & 1 deletion examples/simple_post.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from datetime import datetime
from datetime import timezone

from chitose import BskyAgent
from chitose.app.bsky.feed.post import Post

Expand All @@ -8,7 +10,8 @@ def main():
agent = BskyAgent(service='https://bsky.social')
agent.login(identifier='YOUR_USERNAME', password='YOUR_PASSWORD')

record = Post(text='Hello, world!', created_at=datetime.now().isoformat())
record = Post(text='Hello, world!',
created_at=datetime.now(timezone.utc).isoformat())
agent.post(record=record)


Expand Down
5 changes: 3 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
from datetime import timezone
import argparse
import json
import os
Expand Down Expand Up @@ -123,7 +124,7 @@ def main() -> None:
parser_post.add_argument('--reply', default=None)
parser_post.add_argument('--embed', default=None)
parser_post.add_argument(
'--created_at', default=datetime.now().isoformat())
'--created_at', default=datetime.now(timezone.utc).isoformat())
parser_post.set_defaults(func=_post)

parser_repost = subparsers.add_parser('repost')
Expand All @@ -134,7 +135,7 @@ def main() -> None:
parser_repost.add_argument('--swap-commit', default=None)
# record
parser_repost.add_argument(
'--created_at', default=datetime.now().isoformat())
'--created_at', default=datetime.now(timezone.utc).isoformat())
# strong_ref
parser_repost.add_argument('--uri')
parser_repost.add_argument('--cid')
Expand Down

0 comments on commit db462d5

Please sign in to comment.