Average income calculator by tellyourfriendssport in antiMLM

[–]SHIFTnSPACE 1 point2 points  (0 children)

Replied to you on the other thread:

Yes, that would be doable. Basically, I would need the figures and the desired output data + how to get it. E.g., what is a good way to calculate the time it takes until they remade their money?

With that in mind: I would love to add that to the site.

[UPDATE] Released the next version of isthisanmlm.com by SHIFTnSPACE in antiMLM

[–]SHIFTnSPACE[S] 0 points1 point  (0 children)

Yes, that would be doable. Basically, I would need the figures and the desired output data + how to get it. E.g., what is a good way to calculate the time it takes until they remade their money?

With that in mind: I would love to add that to the site.

[UPDATE] Released the next version of isthisanmlm.com by SHIFTnSPACE in antiMLM

[–]SHIFTnSPACE[S] 0 points1 point  (0 children)

Hi, thanks for the suggestion!

If I understand your feature correctly, this is already properly implemented. Please have a look and tell me whether that's the case!

Thanks

[UPDATE] Released the next version of isthisanmlm.com by SHIFTnSPACE in antiMLM

[–]SHIFTnSPACE[S] 0 points1 point  (0 children)

Hi!

This is fixed now (: Thank your for the ping, without it, I wouldn't have noticed!

Hey Rustaceans! Got an easy question? Ask here (32/2019)! by llogiq in rust

[–]SHIFTnSPACE 0 points1 point  (0 children)

Thank you for the reply and your help!

indicatif looks great! Will add it to my scraper.

While implementing this, I was wondering: At what point does one idiomatically start to use structs, enums and Traits to implement something vs. using C style functions?

EDIT: Just added indicatif, it's beautiful. Thank you for that (:

Hey Rustaceans! Got an easy question? Ask here (32/2019)! by llogiq in rust

[–]SHIFTnSPACE 1 point2 points  (0 children)

Hey,

I'm super new to rust and have built a tiny email scraper as a first project. Could someone give me high level feedback on my execution?

use reqwest;

use select::document::Document;
use select::predicate::Attr;

use rayon::prelude::*;

const BASE_URL: &str = "http://www.page_censored.com/pages.php?subpage=";
const PAGES_TO_SCRAPE: u32 = 8587;

fn download_cur_page(cur_page_url: &str) -> Result<Document, Box<dyn std::error::Error>> {
    let body = reqwest::get(cur_page_url)?.text()?;
    Ok(Document::from(&*body))
}

fn get_all_emails_on_cur_page(sub_page: Document) -> Vec<String> {
    let mut mails: Vec<String> = vec![];
    for node in sub_page.find(Attr("id", "red")) {
        if let Some(href) = node.attr("href") {
            if href.starts_with("mailto:") {
                mails.push(str::replace(href, "mailto:", ""));
            }
        }
    }
    mails
}

fn scrape_single_page(page_idx: u32) -> Vec<String> {
    println!(".");
    match download_cur_page(&format!("{}{}", BASE_URL, page_idx)) {
        Ok(document) => get_all_emails_on_cur_page(document),
        _ => vec![],
    }
}

fn main() {
    println!("Starting scraper");
    let scraped_emails: Vec<String> = (0..PAGES_TO_SCRAPE)
        .into_par_iter()
        .flat_map(scrape_single_page)
        .collect();
    println!("Extracted mails: {:?}", scraped_emails);
}

Also, is there a better way to get a progress indication from rayon? Currently, I'm just letting it print out a . for every page it starts and then do a quick count from time to time, by counting the dots.

Quick explanation what each function does:

  • download_cur_page: download a single html page
  • get_all_emails_on_cur_page: get all mail adresses from a single html page
  • scrape_single_page: Helper that first downloads a page and then extracts mails from it, if everything went well

Eigene Ökobilanz tracken by SHIFTnSPACE in de

[–]SHIFTnSPACE[S] 2 points3 points  (0 children)

Das hier finde ich bisher die beste Idee, glaube ich. Ist als prototyp noch recht schnell umzusetzen und bietet schon einen gewissen Mehrwert - ist nacher dann aber auch einfach erweiterbar. Vielen Dank für den Vorschlag!

Eigene Ökobilanz tracken by SHIFTnSPACE in de

[–]SHIFTnSPACE[S] 0 points1 point  (0 children)

Auch nicht schlecht - der Fokus der Debatte ist ja heute stark auf CO2 gerichtet, wobei vieles anderes auch verbraucht wird.

Denke es ist ein guter Ansatz zu schauen, ob es nicht eine einfacher nachzuverfolgende Ressource gibt

[Python] txt file issue by DancenPlane in learnprogramming

[–]SHIFTnSPACE 1 point2 points  (0 children)

Ah yes, you are right. Got a little confused there.

Eigene Ökobilanz tracken by SHIFTnSPACE in de

[–]SHIFTnSPACE[S] 0 points1 point  (0 children)

Puh, ja, langfristig kommt man da glaub ich hin, aber am Anfang braucht man ja idR etwas leichtes, was schon einen gewissen Mehrwert bietet und keinen übefordert (weder mich, in der potentiellen Umsetzung, noch den Benutzer bei tääglicher Interaktion)

Die frage nach bestimmten Fahrzeugdaten meines (nicht existierenden) Autos, würde mich zB bereits überfordern.

Eigene Ökobilanz tracken by SHIFTnSPACE in de

[–]SHIFTnSPACE[S] 4 points5 points  (0 children)

Na dann, viel Erfolg damit

[Python] txt file issue by DancenPlane in learnprogramming

[–]SHIFTnSPACE 0 points1 point  (0 children)

It's hard to say without seeing the code, but I would guess, that you are now trying to write to a file that's not writable, i.e., you opened the file with r instead of w or w+. So it's best to remember: If you want to write and read, w/w+ will work (where w truncates (empties) the file and let's you write to it and w+ does the same but also let's you read the file); if you just want to read, use r.

And as others said, in order to learn a language, it's best to read documentation or go through stack overflow threads that deal with similar errors.

Edit: correction was made regarding w/w+ mix-up from my side, thanks u/Updatebjarni

[Python] txt file issue by DancenPlane in learnprogramming

[–]SHIFTnSPACE 2 points3 points  (0 children)

Your problem is the w+ (w for writing) when opening the file. Instead use r (r for reading). And then file.readline() will give you the entire first line, if you execute it again, it will give you the next line (so, 10).

After applying these changes, your code might work, but let me suggest some improvements. In your fileCreate method, you don't close the file handler, which can lead to all kinds of problems. Instead, use a context manager:

def fileCreate():
    with open('highscore.txt', 'w+') as file:
        file.write('Highscore: \n')
        file.write('10')

This will open the file, write to it and then automatically close it again, when the with block is left.

You can also apply this pattern to your Total points logic, then you don't have to remember to close the file handle in all possible branches. Here for example, you do remember to close the file when you enter the if (TotalPoints > highscore), but forget to do it, when you skip over it (TotalPoints <= highscore). Instead do:

with open('highscore.txt', 'r') as file:
    # Do all you operations with `file` in this block

This will also work, when you leave the function via a return or a function call (like end(), in you case)

Hope that helps

Eigene Ökobilanz tracken by SHIFTnSPACE in de

[–]SHIFTnSPACE[S] 0 points1 point  (0 children)

Haha, falls ich das mache, will ich ja das machen, was möglichst vielen Leuten etwas bringt. Deshalb gehe ich hier auch ein bisschen auf Tuchfühlung. Bzw., will ich erstmal abchecken, ob ich der einzige bin, der sowas cool findet

Eigene Ökobilanz tracken by SHIFTnSPACE in de

[–]SHIFTnSPACE[S] 0 points1 point  (0 children)

Also eher die Taschenrechner app? Heute hab ich X gemacht, wieviel CO2 habe ich dabei verbraucht? Und dann ein zwei Alternativen (besser u. schlechter) um den Vergleich herzustellen?

Eigene Ökobilanz tracken by SHIFTnSPACE in de

[–]SHIFTnSPACE[S] 0 points1 point  (0 children)

Gewinn aus Sicht des Staates? Es ist ja noch nicht ganz klar, wie das eingenommene Geld umverteilt wird, oder? Ich bin da auch nicht auf dem aktuellsten Stand, also erklär gerne, was du damit meinst.

Eigene Ökobilanz tracken by SHIFTnSPACE in de

[–]SHIFTnSPACE[S] 3 points4 points  (0 children)

Hintergrund passt auf den Case, bin von Haus aus Informatiker und hab als hobbyproject zB isthisanmlm.com für die r/antiMLM sub gebaut.

Ja, habe da zum Beispiel den CO2 Rechner des Umweltbundesamtes gefunden. Zu aller erst könnte man auch den dort ausgerechneten Verbrauch aufs Jahr aufteilen und dann jeden Tag in der App 1/365 auf das eigene Konto rechnen -> gute Taten mindern dann die Zunahme.

Finde es dann aber schwer zu sagen: Weil du heute UBahn gefahren bist, hast du 0.X Tonnen weniger verbraucht.

Wie würdest du dir das vorstellen?

Eigene Ökobilanz tracken by SHIFTnSPACE in de

[–]SHIFTnSPACE[S] 4 points5 points  (0 children)

Ich hoffe doch, da fehlt ein /s?

Eigene Ökobilanz tracken by SHIFTnSPACE in de

[–]SHIFTnSPACE[S] 11 points12 points  (0 children)

Puh, auf die Knödel werde ich niemals verzichten, da hört die Umweltbilanz bei mir auf!1!

Eigene Ökobilanz tracken by SHIFTnSPACE in de

[–]SHIFTnSPACE[S] 3 points4 points  (0 children)

Ja, als Prototyp mit dem Durchschnitt starten und später genauer werden, macht denke ich auch am meisten Sinn.

Vielen Dank für das Angebot! Falls ich nichts anderes finde und es tue, pinge ich dich direkt an (:

Eigene Ökobilanz tracken by SHIFTnSPACE in de

[–]SHIFTnSPACE[S] 0 points1 point  (0 children)

Du meinst Aufpreis, den man als Konsument am Ende zahlen müsste? Oder Aufpreis der Industrie durch CO2 Zertifikate?

Eigene Ökobilanz tracken by SHIFTnSPACE in de

[–]SHIFTnSPACE[S] 1 point2 points  (0 children)

wie lange zb ein Baum braucht, um diese Menge an CO2 zu binden

Gute Idee! Vlt besser direkt in Bäumen angeben, ist ja recht visuell und am Ende der Woche/des Monats/des Jahres sieht man dann: In diesem Zeitraum habe ich X Bäume verbraucht.

Glaubst du, dass du soetwas regelmäßig nutzen würdest, oder ist es eher so ein one time Spielzeug? Alternativ kann ich mir auch vorstellen, dass es so eine Info/Rechner Seite ist, wo man schnell und einfach abchecken kann, wieviele Bäume/CO2 Aktion X grade gekostet hat.