hey yallllll, here is my lil music squares posting script (under the cut)! basically it's a js script and I have a cronjob set on a server for every week at a certain time for it to run. this is more complicated than I think post ppl are gonna want to get but idk just in case any of u wanna use it
import * as dotenv from 'dotenv'
import fs from 'fs'
import path from 'path'
import axios from 'axios'
import cohost from 'cohost'
dotenv.config()
const __dirname = new URL('.', import.meta.url).pathname;
const TEMPFILENAME = 'temp.png'
const timeWeekly = '7day'
const timeMonthly = '1month'
const timeYearly = '1year'
const tapmusicUrl = time => `https://tapmusic.net/collage.php?user=${process.env.LASTFM_HANDLE}&type=${time}&size=4x4&caption=true`
async function chost () {
try {
const headline = 'weekly music squares'
const url = tapmusicUrl(timeWeekly)
const imgData = (await axios.get(url, {
responseType: 'arraybuffer'
})).data
const tempfilepath = path.resolve(__dirname, TEMPFILENAME)
try {
fs.rmSync(tempfilepath)
} catch (err) {}
fs.writeFileSync(tempfilepath, imgData)
let client = new cohost.User();
await client.login(process.env.COHOST_EMAIL, process.env.COHOST_PASSWORD);
const projects = await client.getProjects()
const project = projects.find(p => p.handle === process.env.COHOST_PAGE)
// Create a draft with attachments
// create a draft
const draftId = await cohost.Post.create(project, {
postState: 0,
headline,
adultContent: false,
blocks: [],
cws: [],
tags: []
});
// Upload the attachment
const attachment = await project.uploadAttachment(draftId, tempfilepath);
// 3. Add the attachment block to the draft and publish it
await cohost.Post.update(project, draftId, {
// postState: 0,
postState: 1,
headline,
adultContent: false,
blocks: [{ type: "attachment", attachment }],
cws: [],
tags: ['music squares', 'last.fm', 'weekly music']
});
// console.log(project);
} catch (err) {
console.log(err);
}
}
chost()





