• 1 Post
  • 41 Comments
Joined 8M ago
cake
Cake day: Jan 21, 2022

help-circle
rss

nice catch!
I constantly switch between Js and python, and cant remember the differences lol
yeah, the --help generation is a very convenient part of the libs.
I just wrote this to demonstrate the simplest possible answer.


programming in a nutshell


you have a really simple use-case, so you probably don’t need and argument parsing lib, which I would normally recommend…

You can just iterate through the arguments array and categorize them by type, then add them to the appropriate collection to be handled later.

Something like this:

ids = []
urls = []
csvs = []
for arg in sys.argv:
  if arg.startswith('http'):
    urls.push(arg)
  else if arg.endswith('.csv'):
    csvs.push(arg)
  else:
    ids.push(arg)

Most screenshot tools allow you to pass a name as an argument, so you could make a shell script to generate the name you want then call the screenshotting tool with the appropriate name. Also, consider using flameshot


List of popular Lemmy communities and their alternatives
cross-posted from: https://sopuli.xyz/post/247640 > Just by checking https://lemmy.ml/communities one can see the most popular communities of lemmy.ml. The plan here is to list all the alternatives for those from other instances. One can also suggest alternatives to be added here and I update this living document. > > * [Linux](https://lemmy.ml/c/linux) --> [!linux@heapoverflow.ml](https://heapoverflow.ml/c/linux) > * [Libre Culture](https://lemmy.ml/c/libre_culture) --> ??? > * [Piracy](https://lemmy.ml/c/piracy) --> ???? > * [Open Source](https://lemmy.ml/c/opensource) --> ??? > * [Ask Lemmy](https://lemmy.ml/c/asklemmy) --> [!askwomen@lemmy.ca](https://lemmy.ca/c/askwomen) > * [Privacy](https://lemmy.ml/c/privacy) --> [!privacy@lemmy.ca](https://lemmy.ca/c/privacy), [privacy@community.nicfab.it](https://community.nicfab.it/c/privacy), [privacy@nrsk.no](https://nrsk.no/c/privacy) > * [Technology](https://lemmy.ml/c/technology) --> [!technology@beehaw.org](https://beehaw.org/c/technology), [!technology@gtio.io](https://gtio.io/c/technology) > * [World News](https://lemmy.ml/c/worldnews) --> [!news@beehaw.org](https://beehaw.org/news) > * [Fediverse](https://lemmy.ml/c/fediverse) --> [!fedizens@lemmy.ca](https://lemmy.ca/c/fedizens), > [!thefedizenenquirer@lemmy.ca](https://lemmy.ca/c/thefedizenenquirer), [!fediverse@midwest.social](https://midwest.social/c/fediverse), > [!fediverselore@lemmy.ca](https://lemmy.ca/c/fediverselore), > [!bestofthefediverse@lemmy.ca](https://lemmy.ca/c/bestofthefediverse) > * [Science](https://lemmy.ml/c/science) --> [!science@beehaw.org](https://beehaw.org/c/science), [!science@mander.xyz](https://mander.xyz/c/science), [!science@gtio.io](https://gtio.io/c/science) > * [Memes](https://lemmy.ml/c/memes) --> [!memes@lemmy.ca](https://lemmy.ca/c/memes), [!memes@sopuli.xyz](https://sopuli.xyz/c/memes), [!politicalcompassmemes@lemmy.perthchat.org](https://lemmy.perthchat.org/c/polcompmemes) > * [Gaming](https://lemmy.ml/c/gaming) --> [!gaming@beehaw.org](https://beehaw.org/gaming) > * [Music](https://lemmy.ml/c/music) --> [!music@sopuli.xyz](https://lemmy.ml/c/music), [!music@baraza.africa](https://baraza.africa/c/music), [!music@beehaw.org](https://beehaw.org/c/music) > * [Politics](https://lemmy.ml/c/politics) --> > [!moderatepolitics@sopuli.xyz](https://sopuli.xyz/c/moderatepolitics), [!politics@beehaw.org](https://beehaw.org/c/politics), [!politics@gtio.io](https://gtio.io/c/politics) > * Programming language communities --> [Heapoverflow.ml](https://heapoverflow.ml/communities) > * [Socialism](https://lemmy.ml/c/socialism) --> [!socialism@midwest.social](https://midwest.social/c/socialism) > * [Anarchism](https://lemmy.ml/c/anarchism) --> [!anarchism@lemmy.ca](https://lemmy.ca/c/anarchism) > * [Green](https://lemmy.ml/c/green) --> slrpnk.net, [environment@beehaw.org](https://beehaw.org/c/environment) > * Late Stage Capitalism etc. --> [!aboringdystopia@mander.xyz](https://mander.xyz/c/aboringdystopia)

one size doesnt fit all I guess lol

EDIT: Im down to make changes to the theme tho if you have any other suggestions.


Its not the “effort” its just that my eyes feel sore after staring at a monitor too long, and white backgrounds create eye soreness very quickly.

Are you on a computer all day?

EDIT: I also use a “blue light filter” so I never see actual white even, because it’s unbearable!


I definitely feel like there are ways around that and staring at white backgrounds is extremely fatiguing to my eyes.


what font would you prefer?

EDIT: I figured the monospace font and dark theme would be familiar to most programmers lol

I also figured most people would be “remote viewing” anyway


google prefers results with a bunch of their ads on them =/


Have you tested the throughput of dict.manager?
If you need big scale, there is always redis.


They typically do it for ad revenue, but I’m considering it to prevent people from having to be served ads or use proprietary software to learn programming =/


Typically each project would have unit-tests that cover their own different edge cases, and the one that imports the other would have 1 end-to-end test that covers both functionality but doesn’t explore all of the edge cases.



def convert_video_progress_bar(self, manager, cmd):
    name = self.path.rsplit(os.path.sep, 1)[-1]
    # Run ffmpeg
    proc = expect.spawn(cmd, encoding='utf-8')
    pbar = None
    try:
        # extract the total number of frames 
        proc.expect(pattern_duration)
        total = sum(map(lambda x: float(
            x[1])*60**x[0], enumerate(reversed(proc.match.groups()[0].strip().split(':')))))
        cont = 0
        # keeps track of the progress to show it to the user
        pbar = manager.counter(
            total=100,
            desc=name,
            unit='%',
            bar_format=BAR_FMT,
            counter_format=COUNTER_FMT,
            leave=False
        )
        # infinite loop
        while True:
            # look for a progress indicator, and extract the frame count
            proc.expect(pattern_progress)
            progress = sum(map(lambda x: float(
                x[1])*60**x[0], enumerate(reversed(proc.match.groups()[0].strip().split(':')))))
            # compute the percentage complete
            percent = progress/total*100
            # update the counter, to show the user
            pbar.update(percent-cont)
            cont = percent
    # because of the infinite loop, 
    # `proc.expect` will throw an error once ffmpeg has completed.
    # catch that error, and clean things up
    except expect.EOF:
        traceback.print_exc()
    finally:
        if pbar is not None:
            pbar.close()
    proc.expect(expect.EOF)
    res = proc.before
    res += proc.read()
    # check to see if ffmpeg threw and error
    exitstatus = proc.wait()
    if exitstatus:
        raise ffmpeg.Error('ffmpeg', '', res)

It would be helpful to link the full source like this

It looks like you’re using an older version of the code, so its hard to tell whats happening exactly. can you link it please?

The code is pretty much entirely just using the pexpect library, so you’d need to familiarize yourself with that first. Read the API Overview section of the docs.

Also, a good way of figuring out how code works, is to print() out the variables youre curious about.


I see.

res += "4 " + name The problem here is you’re doing <List> += <str>

Changing it to: res.append('4 ' + name) fixes it


It’s hard to understand what you’re trying to do here…
I would recommend stripping the problem down to a couple lines and explaining what you want and why your code doesn’t work.

If you’re trying to extract information from a string regular expressions are the way to go. You should probably add more to the regexp to capture the name and the percentage, like so:

re.match(r'(.*) \(([0-9]*)%\)', s).groups()


I think if you trimmed the problem down to a couple of lines you’d get a better response =/


You can do it a lot of ways. Use as many or as few files as you want. I figure for this one js file is sufficient.

Parameters would probably be the easiest to learn passing data; In lua, reading and writing to a “subprocess” isn’t trivial. see here, or here.

To simplify it, you could just write comment data to the js script and return errors to lua with “exit codes”.


Ahh, I see, sorry.

The simplest and dumbest way to make this work is to:

  1. make a JS script to make a post
  2. run the script from lua with io.popen
now I will answer your questions:

Does the js client need to be installed in a certain location?

you need to make a “project directory”. Create a new directory the run npm install lemmy-js-client to get started.

Where does the block of text on the api docs go? Just in my bot.lua file?

Make a file named lemmy-post.js and paste this from the api doc into it:

import { LemmyHttp } from 'lemmy-js-client';

let baseUrl = 'https://lemmy.ml';
let client: LemmyHttp = new LemmyHttp(baseUrl, headers?);
let jwt = await client.httpLogin(loginForm).jwt;

websocket or http? Does it matter?

websockets are good for persistent connections, but since your lua-bot will will be calling the script to do one-off tasks I would stick with the HTTP API

I need to make a POST request to lemmy to uyt the content there after I grab the comment from discord?

Presumably the lua-bot will have the content of the discord comment, so you just need to pass it to the JS script which will post it to lemmy.

Can someone recommend me a resource so I can learn more about using the API here?

I would recommend just playing around with the js-client in that script. run it like this: node lemmy-post.js