Linus2punkt0 / bluesky-crossposter

An app for crossposting your posts from bluesky to twitter and mastodon
108 stars 23 forks source link

Fails because database.json doesn't exist #10

Closed ineffyble closed 1 year ago

ineffyble commented 1 year ago

There's a check in jsonRead() for if the database file actually exists, but none in isInDB(). This means that when I try to run, it crossposts, then isInDB() throws, nothing is written, and it repeats on next run.

On a less substantial note it also failed initially because my logs and images dirs didn't exist, but that was just a case of mkdir.

Linus2punkt0 commented 1 year ago

Whoops, hadn't tried running a clean install of the code in a while. Added a check now!

Linus2punkt0 commented 1 year ago

Completely missed that you had already made a pull request, still a little green on github.

MedPlex98 commented 1 year ago

Hey, I have just reinstalled everything and the problem still occurs:

`root@crossposter:~/myapps/crossposter/bluesky-crossposter# python crosspost.py 01/10/2023 02:20:02: Gathering posts

01/10/2023 02:20:02: Posted to twitter

01/10/2023 02:20:04: Posted to mastodon

01/10/2023 02:20:04: Adding to database: {"skeet": "xxx", "ids": {"twitterId": "xxx", "mastodonId": xxx}, "failed": {"twitter": 0, "mastodon": 0}}

Traceback (most recent call last): File "/root/myapps/crossposter/bluesky-crossposter/crosspost.py", line 519, in updates = post(posts) File "/root/myapps/crossposter/bluesky-crossposter/crosspost.py", line 246, in post jsonWrite(cid, tweetId, tootId, {"twitter": tFail, "mastodon": mFail}) File "/root/myapps/crossposter/bluesky-crossposter/crosspost.py", line 407, in jsonWrite file = open(databasePath, append_write) FileNotFoundError: [Errno 2] No such file or directory: '/db/database.json' (venv) root@crossposter:~/myapps/crossposter/bluesky-crossposter# `

Linus2punkt0 commented 12 months ago

You seem to have an incorrectly given basePath in paths.py, I'm guessing it's set to just "/" instead of the actual path to the project. Right now it is trying to write to the file database.json in the folder "/db", which I am assuming does not exist. So you should update the basePath or create the folder if that is where you want it saved.

MedPlex98 commented 12 months ago

Okay, right. I have now set the path. But meanwhile I get another error xD

The path is set in the paths.py and the folder "logs" also exists

python3 crosspost.py 02/10/2023 17:20:04: Gathering posts

Traceback (most recent call last): File "/root/myapps/crossposter/bluesky-crossposter/crosspost.py", line 518, in posts = getPosts() File "/root/myapps/crossposter/bluesky-crossposter/crosspost.py", line 37, in getPosts writeLog("Gathering posts") File "/root/myapps/crossposter/bluesky-crossposter/crosspost.py", line 455, in writeLog dst = open(log, append_write) FileNotFoundError: [Errno 2] No such file or directory: '/myapps/crossposter/bluesky-crossposter/logs/231002.log'

But thanks so far @Linus2punkt0 for your help!

Linus2punkt0 commented 12 months ago

From what I can see the app is running in "/root/myapps/crossposter/bluesky-crossposter/", but the path specified for logs is "/myapps/crossposter/bluesky-crossposter/logs/", so it can't find the folder.

MedPlex98 commented 12 months ago

Right, my mistake. I have now adjusted it and now get the next error. Sorry if I am perhaps a little unknowing 🙈

root@crossposter:~/myapps/crossposter/bluesky-crossposter# python3 crosspost.py Traceback (most recent call last): File "/root/myapps/crossposter/bluesky-crossposter/crosspost.py", line 517, in database = jsonRead() File "/root/myapps/crossposter/bluesky-crossposter/crosspost.py", line 418, in jsonRead jsonLine = json.loads(line) File "/usr/lib/python3.9/json/init.py", line 346, in loads return _default_decoder.decode(s) File "/usr/lib/python3.9/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)

Linus2punkt0 commented 12 months ago

I'm not entirely sure why you are getting that error but I believe it's because a database-file has been created but is empty. I wrote a small fix that should avoid this error, just download the new version of crosspost.py and try running it again.

cainthebest commented 12 months ago

I had a look at it myself and was able to fix it here in a quick fork. @Linus2punkt0 I was going to put a PR in but it seems you have tried to already address it.