Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Grabbing text by line

I am in the middle of making a discord bot. I am wanting to go get to a pastebin link and grab some account info and then send that to the user. BUT I want to grab like one set of credentials at a time. Basically by line and ideally random aswell. I know how to do all but the part of randomizing what its grabbing aswell as having it grabbed by one line
Make the request
Read the response
Split the text at \r\n
Each result from above is a line

Return splitRes[Math.random(0,len(splitRes))]
PHP Code

<?php 
# -*- coding: utf-8 -*-

import typing
import asyncio

from random import shuffle
from aiohttp import ClientSession

class API:
    
def __init__(self):
        
self._session = ClientSession()

    
async def request(self, method: str, url: str, **kwargs) -> str:
        
async with self._session.request(method, url, **kwargs) as request:
            return 
await request.text()

    
async def close(self):
        
await self._session.close()

    
async def __aenter__(self) -> 'API':
        return 
self

    async def __aexit__
(self, *args):
        
await self.close()


class 
Pastebin(API):
    
def __init__(self):
        
super().__init__()

    
async def raw(self, paste: str) -> str:
        return 
await self.request("GET", f"https://pastebin.com/raw/{paste}")


async def shuffled_data(paste: str) -> typing.List[str]:
    
async with Pastebin() as pastebin:
        
data = (await pastebin.raw(paste)).splitlines()
    
shuffle(data)
    return 
data

async def main
():
    
paste = input("Paste => ")
    print(
await shuffled_data(paste))
    
if 
__name__ == "__main__":
    
asyncio.run(main()) 
I eneded up sorting it out. But basically I just used the random module and split it into a list to randomly grab one


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by HammyleinMar 30, 2022 12:37 PM 4 255 Mar 30, 2022 12:37 PM
Last Post: foxegado
[C#] by Formula 1Dec 6, 2019 01:11 AM 23 699 Dec 6, 2019 01:11 AM
Last Post: itcorp
[C] by VolitairNov 11, 2018 08:53 AM 1 133 Nov 11, 2018 08:53 AM
Last Post: HFDone