PhiTux / DailyTxT

Encrypted Diary Web-App
https://hub.docker.com/r/phitux/dailytxt/
MIT License
224 stars 15 forks source link

I wrote a json converter, from Journey.cloud export to DailyTxt import format #13

Closed xontik closed 2 years ago

xontik commented 2 years ago

Would you be interested in it ? it worked for me i wont use it again so if you want it it's yours

const { promises: fs } = require("fs");
const striptags = require("striptags");

const getFiles = async () => {
  const list = await fs.readdir("./input");

  const data = list.map((name) => {
    const entry = require(`./input/${name}`);
    const date = new Date(+name.split("-")[0]);
    return {
      date,
      text: entry.text,
    };
  });
  const out = {};

  data.forEach((entry) => {
    const month = "" + entry.date.getMonth();
    const year = entry.date.getFullYear();
    if (out[year] === undefined) {
      out[year] = { [month]: { days: [] } };
    } else {
      if (out[year][month] === undefined) {
        out[year][month] = { days: [] };
      }
    }
    const day = entry.date.getDate();

    out[year][month].days.push({
      day,
      text: striptags(entry.text),
      date_written: `${("" + day).padStart(2, "0")}/${("" + month).padStart(
        2,
        "0"
      )}/${year} ${("" + entry.date.getHours()).padStart(2, "0")}:${(
        "" + entry.date.getMinutes()
      ).padStart(2, "0")}`,
    });
  });

  for (const [year, months] of Object.entries(out)) {
    if (!fs.mkdir(`output/${year}`, { recursive: true })) {
      fs.mkdirSync(`output/${year}`);
    }
    for (const [month, days] of Object.entries(months)) {
      fs.writeFile(
        `output/${year}/${("" + month).padStart(2, "0")}.json`,
        JSON.stringify(days),
        { flag: "a+" }
      );
    }
  }
};

getFiles();
PhiTux commented 2 years ago

Wow, that's cool (and I didn't even know that journey.cloud exists until now).

What about the encryption? This is obviously missing, right? But how is your imported text then even working with DailyTxT? Normally all text is saved encrypted in the files and gets decrypted when loading into the browser.

xontik commented 2 years ago

I just converted their exported (and decrypted) JSON into your DailyTxt exported (and decrypted) JSON.

Then I used your restore from zip fonctionality.

My code is bullshit but I thought it could help someone !

PhiTux commented 2 years ago

Ah, thanks for clarification! I didn't read properly concerning the import-functionality.

I think what I would just do: link to this issue and your code from within the readme.

Thanks very much :)