Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
jj0e committed Apr 10, 2020
1 parent bc93656 commit 6e744f2
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 1 deletion.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Joe Cranney

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,57 @@
# whatbot-helper
<p><img src="https://whatbot.club/manual/images/logo.png" width="200" alt="whatbot logo"></p>

__whatbot-helper__ is a lightweight script that makes creating bulk tasks and groups more efficient and allows you to save time setting up. They are currently working on v1.0 which I assume will have something like this, however in the meantime feel free to use this. We are in no way affiliated with What Bot, you can find their official twitter page [here.](https://www.twitter.com/whatbotisthis)

# Getting Started

### Prerequisites

1. Fill out the task sheet [here](https://docs.google.com/spreadsheets/d/1kQetYxE-hNpLmeTGfuG9--M7yNo2JRNHYLdF3ws247c/edit?usp=sharing) and download as .xlsx
2. Install Python 3 [here](https://www.python.org/downloads/release/python-368/) and be sure to add to path during installation.
Once you have installed Python, download the repository.

The task sheet is pretty self-explanatory however if you would like to have multiple tasks in the same group, simply make the ``group name`` the same and when you run the script it will automatically group the tasks.


### Install
```python
pip install -r requirements.txt
```

### Usage
There are 3 main files that are involved within the whatbot task creation process. These files are billing.db, groups.db, and tasks.db

###### **billing.db**
Contains all of your profiles

###### **groups.db**
Contains all of the task groups

###### **tasks.db**
Contains all of your tasks

I mention this because it is important to understand what is needed for whatbot to understand your info. You will need to locate the billing.db file because it is needed in order to create your tasks.

#### Finding billing.db
Operating System | Path
---------------- | ----
MacOS | Library/Application Support/WhatBot/billing.db
Windows | TBD

_This folder is very important so make sure you can locate it, you will need it again._

Drag the billing.db file into the ``config`` folder and open you terminal or cmd and type:
```python
python3 main.py
```

This will run the program. If you missed a step, you will get an error message telling you what is needed.

#### After script successfully runs
After it runs you will get a message saying: ``Done. Read instructions for next steps.`` At this point you need to navigate to the ``config`` folder and you will see 3 files. ``billing.db``, ``tasks.db``, and ``groups.db``. You will need to copy and paste these files into the whatbot folder from earlier where you got your original ``billing.db`` folder.

---

### Support

Feel free to contact me on Twitter [@atcbackdoor](https://www.twitter.com/atcbackdoor) if you are facing any issues or bugs. Please do NOT DM if you have not read the instructions, I will ignore.
35 changes: 35 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Author: Joe Cranney
Project Title: Whatbot Helper
Project Description: Makes bulk task creation with What Bot a little more efficient
Date Created: 4/9/2020
Last Edited: 4/9/2020
"""

import sys
from whatbot import helper
from datetime import datetime

if __name__ == "__main__":
print(f"[{datetime.now().strftime('%H:%M:%S.%f')}] - WHATBOT HELPER")
print(f"[{datetime.now().strftime('%H:%M:%S.%f')}] - Created by @atcbackdoor")

try:
helper.validate_files()
except Exception as e:
print(f"[{datetime.now().strftime('%H:%M:%S.%f')}] - {e}")
sys.exit()

file_name = input(f"[{datetime.now().strftime('%H:%M:%S.%f')}] - Enter spreadsheet filename: ")

try:
tasks = helper.parse_tasks_from_spreadsheet(file_name)
h = helper.Helper()
h.write_tasks_to_files(tasks)
except Exception as e:
helper.rename_files()
print(f"[{datetime.now().strftime('%H:%M:%S.%f')}] - {e}")
sys.exit()

helper.rename_files()
print(f"[{datetime.now().strftime('%H:%M:%S.%f')}] - Done. Read instructions for next steps.")
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xlrd
Empty file added whatbot/__init__.py
Empty file.
157 changes: 157 additions & 0 deletions whatbot/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
"""
Author: Joe Cranney
Project Title: Whatbot Helper
Project Description: Makes bulk task creation with What Bot a little more efficient
Date Created: 4/9/2020
Last Edited: 4/9/2020
"""

import os
import xlrd
import random
import string
import json


# Returns all tasks in provided xlsx file
def parse_tasks_from_spreadsheet(file_name):
if ".xlsx" not in file_name:
raise Exception("File name does not have .xlsx")
else:
workbook = xlrd.open_workbook("./config/" + file_name).sheet_by_index(0)
items = []
for row in range(1, workbook.nrows):
name = workbook.cell(row, 0).value
site = workbook.cell(row, 1).value
sku = workbook.cell(row, 2).value
one_checkout = workbook.cell(row, 3).value
head_start = workbook.cell(row, 4).value
size = workbook.cell(row, 5).value
profile_name = workbook.cell(row, 6).value

data = {
"name": name,
"site": site,
"sku": sku,
"one_checkout": one_checkout,
"head_start": head_start,
"size": size,
"profile_name": profile_name
}

items.append(data)

return items


def validate_files():
if not os.path.exists("./config/billing.db"):
raise Exception("billing.db does not exist in config, read instructions.")
if os.path.exists("./config/groups.db"):
os.remove("./config/groups.db")
if os.path.exists("./config/tasks.db"):
os.remove("./config/tasks.db")
if os.path.exists("./config/groups.txt"):
os.remove("./config/groups.txt")
if os.path.exists("./config/tasks.txt"):
os.remove("./config/tasks.txt")

os.rename("./config/billing.db", "./config/billing.txt")


def rename_files():
os.rename("./config/billing.txt", "./config/billing.db")
os.rename("./config/groups.txt", "./config/groups.db")
os.rename("./config/tasks.txt", "./config/tasks.db")


class Helper:

def __init__(self, billing_db_path="./config/billing.txt", groups_db_path="./config/groups.txt",
tasks_db_path="./config/tasks.txt"):
self.billing_db = billing_db_path
self.groups_db = groups_db_path
self.tasks_db = tasks_db_path
open(self.groups_db, "w+")
open(self.tasks_db, "w+")

def get_billing_id(self, billing_name):
for profile in open(self.billing_db):
p = json.loads(profile)
if p["name"] == billing_name:
return p["_id"]

raise Exception("Provided billing name does not exist in billing.db")

def create_group(self, task):
name = task["name"]
head_start = task["head_start"]
one_checkout = task["one_checkout"]
site = task["site"]
sku = task["sku"]

group = {
"_id": ''.join(random.choices(string.ascii_letters + string.digits, k=16)),
"advanced": False,
"customScrapers": [],
"keywordsLink": sku,
"name": name,
"oneCheckoutPerProfile": eval(one_checkout),
"preloadHeadstart": str(int(head_start)),
"restockMode": "BRUTE",
"scrapers": [],
"siteId": site,
"proxySetId": "none"
}

with open(self.groups_db, "a+") as f:
json.dump(group, f)
f.write("\n")

return group["_id"]

def write_tasks_to_files(self, data):
for task in data:
group_found = False

# Check to see if the group is already made
for group in open(self.groups_db):
g = json.loads(group)
if task["name"] == g["name"]:
group_found = True

task_data = {
"_id": ''.join(random.choices(string.ascii_letters + string.digits, k=16)),
"groupId": g["_id"],
"size": task["size"],
"billing": self.get_billing_id(task["profile_name"]),
"username": "",
"password": "",
"flavor": "base",
"preload": True,
"enabled": True
}

with open(self.tasks_db, "a+") as f:
json.dump(task_data, f)
f.write("\n")

if not group_found:
# The group has not been made, therefore it needs to be
group_id = self.create_group(task)

task_data = {
"_id": ''.join(random.choices(string.ascii_letters + string.digits, k=16)),
"groupId": group_id,
"size": task["size"],
"billing": self.get_billing_id(task["profile_name"]),
"username": "",
"password": "",
"flavor": "base",
"preload": True,
"enabled": True
}

with open(self.tasks_db, "a+") as f:
json.dump(task_data, f)
f.write("\n")

0 comments on commit 6e744f2

Please sign in to comment.