[serious] Python (Programming Language) users

Discussion in 'Off Topic Discussion' started by Xproplayer, Sep 1, 2018.

  1. Xproplayer

    Xproplayer VIP Silver

    Any folks who know python besides @PixeL who can assist with some intros for me? I have some javascript fundamentals down so its not a difficult transition. Currently trying to learn some BeautifulSoup, how to launch steam games, timers, and maybe some notifications. But I am trying to learn, not have code written for me.

    Serious replies only
     
    Last edited: Sep 2, 2018
    • Like Like x 1
  2. The Cuddle Team Leader

    The Cuddle Team Leader Banned Elite

    Look up ''python programming to send adware into a computer.'' thank me later.
     
    Last edited: Sep 1, 2018
    • Dumb Dumb x 6
  3. Xproplayer

    Xproplayer VIP Silver

    Threads kinda dead but lemme revive it with 4 cool things Pixel helped me make.

    First:
    Grabs a random image from https://earthview.withgoogle.com (roughly 1500 available images, all SFW) and sets your clipboard to a discord and shoutbox friendly img tag.
    Code:
    import requests
    import random
    import win32clipboard as clip
    
    while True:
        rand = random.randint(1000,7023)
        url = 'https://www.gstatic.com/prettyearth/assets/full/' + str(rand) + '.jpg'
    
        r = requests.get(url)
        if r.status_code != 200:
            continue
        else:
            clip.OpenClipboard()
            clip.EmptyClipboard()
            clip.SetClipboardText('[img]'+url+' [/img]')
            clip.CloseClipboard()
            break
    
    Next:
    Auto check if a specific player is connected to the servers (In my case its my alt) and if not, notify the user by leaving the window open (runs hourly)
    Code:
    import requests
    from bs4 import BeautifulSoup
    
    result = requests.get("https://www.seriousgmod.com/servers/")
    
    c = result.content
    b = result.text
    
    username = "SGM DarkRP"
    
    if username in b:
        print('found')
    else:
        input('Not found, please confirm')
    
    soup = BeautifulSoup(c, 'html.parser')
    
    samples = soup.find_all("tbody")
    
    
    Next:
    Automatically finds the emptiest server and joins it for AFKing for points
    TURNS OUT THIS KINDA SUX CAUSE PTS WAS ADDED, NEW VERSION IS BEING TESTED
    Code:
    import requests
    import webbrowser
    
    result = requests.get("https://www.seriousgmod.com/servers/json")
    r = result.json()
    
    sort = sorted(r['servers'], key=lambda k: k['num_players'])
    
    if sort[0]['ip'] == 'east.seriousdr.com':
        ip = sort[1]['ip']
    else:
        ip = sort[0]['ip']
    
    print(ip)
    
    url = "steam://connect/" + ip
    
    webbrowser.open(url,0)
    And last:
    Download the 1523 images from earthview to a folder for desktop usage :D
    Code:
    #!/usr/bin/env python
    
    import os
    import requests
    
    BASE_URL = 'https://www.gstatic.com/prettyearth/assets/full/'
    SAVE_DIR = 'earthview_pictures'
    
               
    def downloadfullimage(url, file_name):
        response = requests.get(url)
        if response.status_code != 200:
            print(f'Status Code: {response.status_code}')
            return
        with open(f'{SAVE_DIR}/{file_name}', 'wb') as file:
            file.write(response.content)
            print(f'Wrote file {file_name}')
    
           
    
    def get_images():
        if not os.path.exists(SAVE_DIR):
            print('Creating save folder...')
            os.makedirs(SAVE_DIR)
    
        for x in range(1003, 7023):
            print(f'Fetching image {x}...')
            url = f'{BASE_URL}{x}.jpg'
            downloadfullimage(url, f'{x}.jpg')
    
    get_images()
    
     
    Last edited: Sep 7, 2018
    • Winner Winner x 2
    • Like Like x 1
    • Useful Useful x 1
    • Creative Creative x 1