R-Kioski freebie script

4. helmikuuta 2022 | 228 näyttökertaa

import requests
import random

from time import sleep
from bs4 import BeautifulSoup

# implement support for https://receive-sms.cc/Finland-Phone-Number/

# kokeile näillä lisää yhdistelmiä

discord_web_hook = ""

# r = requests.get('https://pastebin.fi/r/odllNzfNAV3X/')
r = requests.get('https://www.r-kioski.fi/')
soup = BeautifulSoup(r.text, features="lxml")

def check_for_new_campaign(soup):
  try:
    title = soup.find('div', {'class': 'sampling-campaign-body__left'}).find('h1').text
  except Exception as e:
    return (False, False)

  try:
    description = soup.find('div', {'class': 'sampling-campaign-content'}).text
  except Exception as e:
    return (False, False)

  return (title, description)

def find_campaign_info(soup):
  try:
    nonce = soup.find('input', {'id': 'campaign-contacs-nonce'}).get('value')
  except Exception as e:
    return (False, False)
    
  try:
    campaign_id = soup.find('input', {'name': 'campaign_id'}).get('value')
  except Exception as e:
    return (False, False)
  
  return (nonce, campaign_id)

def notify_of_campaign(title, description, nonce, campaign_id):
  infoMessage = "New campaign found: " + title + "\n\n" + description + "\n\nNonce:" + nonce + "\n\nCampaign ID:" + campaign_id

  print('New campaign found:\n')
  print('Title: ' + title)
  print('Description: ' + description)
  print('Nonce: ' + nonce)
  print('Campaign ID: ' + campaign_id)
  print('\n')
  print('Sending message to Discord...')
  print('----------------------------------------')

  requests.post(discord_web_hook, data={'content': infoMessage})

def get_random_kiosk(soup):
  try:
    kiosks_html = soup.find('div', {'id': 'js-KioskList'}).findAll('option')
    kiosk_id = kiosks_html[random.randint(0, len(kiosks_html) - 1)].get('value')
  except Exception as e:
    return False
  return kiosk_id

def receive_freebies(nonce, campaign_id, phone_number, kiosk_id):
  data = [
    ('campaign-contacs-nonce', nonce),
    ('action', 'sampling_campaign_contacts'),
    ('campaign_id', campaign_id),
    ('phone', phone_number),
    ('city', 'Helsinki'),
    ('kiosk', kiosk_id),
    ('sex', 'male'),
    ('age', '16-19'),
  ]

  response = requests.post('https://www.r-kioski.fi/wordpress/wp-admin/admin-ajax.php', data=data)
  return response.text

def get_phone_number_combinations(phone_number):
  # phone number should be in format 401234567
  phone_number_combinations = []
  phone_number_combinations.append("0" + phone_number)
  phone_number_combinations.append("+358" + phone_number)
  phone_number_combinations.append("+(358)0" + phone_number)
  phone_number_combinations.append("00+(358)0" + phone_number)
  phone_number_combinations.append("00(+358)(+358)" + phone_number)
  phone_number_combinations.append("00(+358)(+358)0" + phone_number)
  phone_number_combinations.append("00+358" + phone_number)

  # ei vahvistettu
  # phone_number_combinations.append("(+358)(+358)0" + phone_number)
  return phone_number_combinations

def check_campaign_used(campaign_id):
  with open('campaigns.txt') as f:
    for line in f:
      if str(campaign_id) == line.replace('\n', ''):
        return True
  return False

def mark_campaign_used(campaign_id):
  f = open("campaigns.txt", "a")
  f.write("\n" + str(campaign_id))
  f.close()

if __name__ == "__main__":
  requests.post(discord_web_hook, data={'content': 'I have started!'})

  print("Starting...")
  print("----------------------------------------")
  print("")
  print("Ultimate R-kioski freebie bot")
  print("Made with love by @Erikoisjaakari#4676")
  print("")
  print("----------------------------------------")
  while True:
    (title, description) = check_for_new_campaign(soup)
    (nonce, campaign_id) = find_campaign_info(soup)

    if title and not check_campaign_used(campaign_id):
      notify_of_campaign(title, description, nonce, campaign_id)
      with open('numbers.txt') as f:
        for line in f:
          original_phone_number = line.strip()
          phone_numbers = get_phone_number_combinations(original_phone_number)
          kiosk_id = get_random_kiosk(soup)

          for phone_number in phone_numbers:
            result = receive_freebies(nonce, campaign_id, phone_number, kiosk_id)
            phone_submission_result = '------------------------\n' + 'Tried to send message to ' + phone_number + " with result: " + result + '\n------------------------'
            print(phone_submission_result)
            requests.post(discord_web_hook, data={'content': phone_submission_result})

          print('Phone number: ' + original_phone_number)
          print('Kiosk ID: ' + kiosk_id)
          print('----------------------------------------')
      # mark_campaign_used(campaign_id)

    sleep(60)