Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deactivation not working #5

Open
blendaddict opened this issue Aug 30, 2023 · 1 comment
Open

Deactivation not working #5

blendaddict opened this issue Aug 30, 2023 · 1 comment

Comments

@blendaddict
Copy link

blendaddict commented Aug 30, 2023

I tried running the script on my ad with only the deactivation part ("deactivated" : 1) like this

import getpass
import time

import requests
from bs4 import BeautifulSoup


class WGGesuchtSession(requests.Session):
    def login(self, user, password):
        
        url = "https://www.wg-gesucht.de/ajax/sessions.php?action=login"
        data = {"login_email_username": user,
                "login_password": password,
                "login_form_autologin": "1",
                "display_language": "en"}
        self.post(url, json=data)
        response = self.get("https://www.wg-gesucht.de/meine-anzeigen.html")
        soup = BeautifulSoup(response.text, features="html.parser")
        nodes = soup.select("a.logout_button")

        self.csrf_token = nodes[0]['data-csrf_token']
        nodes = soup.select("a.logout_button")
        self.user_id = nodes[0]['data-user_id']

    def toggle_activation(self, ad_id):
        
        api_url = "https://www.wg-gesucht.de/api/offers/{}/users/{}".format(ad_id, self.user_id)
        headers = {"X-User-ID": self.user_id,
                   "X-Client-ID": "wg_desktop_website",
                   "X-Authorization": "Bearer " + self.cookies.get("X-Access-Token"),
                   "X-Dev-Ref-No": self.cookies.get("X-Dev-Ref-No")}
        data = {"deactivated": "1", "csrf_token": self.csrf_token}
        r = self.patch(api_url, json=data, headers=headers)
        print("deactivated ad")
        data["deactivated"] = "0"
        # r = self.patch(api_url, json=data, headers=headers)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description='Keep WG-Gesucht.de ads on top of the listing by regularly toggling their activation status.')
    parser.add_argument("--interval", nargs=1, type=int, default=3600, help="How often to update the ads. Interval in seconds, default 3600 (1h).")
    parser.add_argument("ad_id", nargs="+", help="The IDs of the ads.")
    args = parser.parse_args()
    username = input("username:")
    password = getpass.getpass("password:")
    while True:
        session = WGGesuchtSession()
        session.login(username, password)
        for ad_id in args.ad_id:
            print("toggling activation")
            session.toggle_activation(ad_id)
        time.sleep(args.interval)```
 But it did not deactivate the ad. Anyone know whether that is still possible?
@SebastKl
Copy link

The deactivating and reactivating definitely works like a charm.
I think, there is probably a problem with the X-Access-Token and the X-Dev-Ref-No Token.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants