Skip to content

Commit

Permalink
add get option.
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserbdj96 authored May 28, 2022
1 parent b7a8bb0 commit 99e7b79
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
- New build.

## 0.0.1
- First public release.
- First public release.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Default json code:
"url":"<WEBSITE_URL>",
"<OPIRATION_TITLE>":{
"operations":[
{"type":"<xpath/link_text/id/name/tag_name>","code":"<ELEMENT_CODE>","arg_code":"[n]","opt":"<click/put>","arg_data":"[n]","data":"<YOUR_DATA>"}
{"type":"<xpath/link_text/id/name/tag_name>","code":"<ELEMENT_CODE>","arg_code":"[n]","opt":"<click/put/get>","arg_data":"[n]","data":"<YOUR_DATA>"}
]
}
}
Expand All @@ -50,6 +50,7 @@ Help:
# If you don't use the 'code' key, you must use the 'arg_code' key to enter data from your script.
# If you don't use the 'data' key, you must use the 'arg_data' key to enter data from your script.
# When using the 'put' option you must use 'data' or 'arg_data', Unlike the "click" option.
# When using the 'get' option you must use 'data' or 'arg_data', Unlike the "click" option, data=get_attribute("<src/herf/name/id>").
# 'arg_data' and 'arg_code' are numbers.
# 'arg_data' and 'arg_code' are the order of the element to be inserted from the list. //Example: p1.run(<OPIRATION_TITLE>,n0,n1,n2....n)
# 'data' and 'code' for entering data like password or username from json file (this is a common option if the variables you want to use are static).
Expand All @@ -62,6 +63,7 @@ Help:
from imbot import *

# Examples
# Example 1:
# Open the website link:
p1=imbot("github.json")

Expand All @@ -85,8 +87,9 @@ p1.run("login",'<YOUR_PASSWORD>')
Lines=open('list.txt','r').readlines()

# Strips the newline character
for i in range(len(Lines)):
repositorie=Lines[i].strip()
#for i in range(len(Lines)):
for i, Line in enumerate(Lines):
repositorie=Line.strip()
# To the repositorie:
p1.run("go2repositorie",repositorie)# repositorie=="arg_code":"0" //Bearing in mind that the order of the variable is 0
# make operations:
Expand All @@ -96,6 +99,17 @@ for i in range(len(Lines)):

# end
p1.end()

# Example 2:
# Open the website link:
p2=imbot("google.json")

# Here, search for a movie poster in Google Images and get the link:
print(p2.run("search","Game.Of.Thrones.Conquest.And.Rebellion.2017"))
print(p2.run("search","DEJA.VU.2018"))

# end
p2.end()
```

<h2>Screenshot:</h2>
Expand All @@ -109,6 +123,10 @@ p1.end()
<h2>Changelog History:</h2>

```
## 0.1.3 [28-05-2022]
- Add Return 'get_attribute' as a list.
- Fix bugs.
## 0.1.2 [10-03-2022]
- Fix bugs.
Expand Down
79 changes: 79 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# docker build -t imbot .
# docker run -i -t imbot
#
FROM ubuntu
LABEL maintainer "Sean Pianka <[email protected]>"

## For chromedriver installation: curl/wget/libgconf/unzip
RUN apt-get update -y && apt-get install -y wget curl unzip libgconf-2-4
## For project usage: python3/python3-pip/chromium/xvfb
RUN apt-get update -y && apt-get install -y xvfb python3 python3-pip


# install manually all the missing libraries
RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils

# install chrome
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install

# Download, unzip, and install chromedriver
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/

# Create directory for project name (ensure it does not conflict with default debian /opt/ directories).
WORKDIR /wrdir

## Your python project dependencies
#RUN pip3 install selenium
## or install from dependencies.txt, comment above and uncomment below
#COPY requirements.txt .
#RUN pip3 install -r requirements.txt


## Copy over project/script (feel free to combine these if your project is a combination of both directories and top-level files)
### For projects which are modules
#COPY app/ .
## For projects which are single scripts
COPY ./examples /wrdir
COPY ./imbot /wrdir/imbot
COPY ./requirements.txt /wrdir/requirements.txt
COPY ./run.sh /wrdir/run.sh

RUN pip install --no-cache-dir --upgrade -r /wrdir/requirements.txt


# Set display port and dbus env to avoid hanging
ENV DISPLAY=:99
ENV DBUS_SESSION_BUS_ADDRESS=/dev/null


# Bash script to invoke xvfb, any preliminary commands, then invoke project
#CMD ["Xvfb",":99","-screen","0","640x480x8","-nolisten","tcp","&&","python3","examples.py"]
#COPY run.sh .
CMD /bin/bash run.sh

#












#FROM python:3.9

#WORKDIR /wrdir

#COPY ./examples /wrdir
#COPY ./imbot /wrdir/imbot
#COPY ./requirements.txt /wrdir/requirements.txt

#RUN pip install --no-cache-dir --upgrade -r /wrdir/requirements.txt

#CMD ["python", "examples.py"]
4 changes: 4 additions & 0 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Reason for "-nolisten tcp", not documented within Xvfb manpages (for who knows what reason)
# https://superuser.com/questions/855019/make-xvfb-listen-only-on-local-ip
Xvfb :99 -screen 0 640x480x8 -nolisten tcp &
python3 examples.py
18 changes: 16 additions & 2 deletions examples/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"url":"<WEBSITE_URL>",
"<OPIRATION_TITLE>":{
"operations":[
{"type":"<xpath/link_text/id/name/tag_name>","code":"<ELEMENT_CODE>","arg_code":"[n]","opt":"<click/put>","arg_data":"[n]","data":"<YOUR_DATA>"}
{"type":"<xpath/link_text/id/name/tag_name>","code":"<ELEMENT_CODE>","arg_code":"[n]","opt":"<click/put/get>","arg_data":"[n]","data":"<YOUR_DATA>"}
]
}
}
Expand All @@ -14,14 +14,17 @@
# If you don't use the 'code' key, you must use the 'arg_code' key to enter data from your script.
# If you don't use the 'data' key, you must use the 'arg_data' key to enter data from your script.
# When using the 'put' option you must use 'data' or 'arg_data', Unlike the "click" option.
# When using the 'get' option you must use 'data' or 'arg_data', Unlike the "click" option, data=get_attribute("<src/herf/name/id>").
# 'arg_data' and 'arg_code' are numbers.
# 'arg_data' and 'arg_code' are the order of the element to be inserted from the list. //Example: p1.run(<OPIRATION_TITLE>,n0,n1,n2....n)
# 'data' and 'code' for entering data like password or username from json file (this is a common option if the variables you want to use are static).
"""

from imbot import *

# Examples
# Example 1:
# Open the website link:
p1=imbot("github.json")

Expand Down Expand Up @@ -56,4 +59,15 @@
p1.run("go2home")

# end
p1.end()
p1.end()

# Example 2:
# Open the website link:
p2=imbot("google.json")

# Here, search for a movie poster in Google Images and get the link:
print(p2.run("search","Game.Of.Thrones.Conquest.And.Rebellion.2017"))
print(p2.run("search","DEJA.VU.2018"))

# end
p2.end()
13 changes: 13 additions & 0 deletions examples/google.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"url":"https://www.google.com/",
"search":{
"operations":[
{"type":"xpath","code":"/html/body/c-wiz/c-wiz/div/div[3]/div[2]/div/div[1]/form/div[1]/div[1]/c-wiz/div/a","opt":"click"},
{"type":"xpath","code":"/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/input","opt":"put","arg_data":"0"},
{"type":"name","code":"btnK","opt":"click"},
{"type":"xpath","code":"/html/body/div[7]/div/div[4]/div/div[1]/div/div[1]/div/div[2]/a","opt":"click"},
{"type":"xpath","code":"/html/body/div[2]/c-wiz/div[3]/div[1]/div/div[1]/div/div[1]/div[1]/span/div[1]/div[1]/div[1]/a[1]/div[1]/img","opt":"click"},
{"type":"xpath","code":"/html/body/div[2]/c-wiz/div[3]/div[2]/div[3]/div/div/div[3]/div[2]/c-wiz/div/div[1]/div[1]/div[3]/div/a/img","opt":"get","data":"src"}
]
}
}
27 changes: 24 additions & 3 deletions imbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self,json_data,sleep_time=2,url=""):
def run(self,goto,*argm):
operations=self.json_data[goto]['operations']
#for i in range(len(operations)):
get_list=[]
for i, operation in enumerate(operations):
try:
#
Expand All @@ -49,6 +50,9 @@ def run(self,goto,*argm):
if operation['opt']=="click":
do="click()"
text=f"[✓] Clicking on element_by_{types} : '{code}'"
exec(f"self.driver.find_element_by_{types}('{code}').{do}")
hexor().c(text,"#299c52")
sleep(self.sleep_time)
#
elif operation['opt']=="put":
#
Expand All @@ -60,10 +64,26 @@ def run(self,goto,*argm):
data=input(hexor(True).c("Data is empty : ","#ff0000"))
do=f"send_keys('{data}')"
text=f"[✓] Putting data to element_by_{types} : '{code}'"
exec(f"self.driver.find_element_by_{types}('{code}').{do}")
hexor().c(text,"#299c52")
sleep(self.sleep_time)
#
exec(f"self.driver.find_element_by_{types}('{code}').{do}")
hexor().c(text,"#299c52")
sleep(self.sleep_time)
elif operation['opt']=="get":
do=""
text=f"[✓] Get data to element_by_{types} : '{code}'"
#
if "arg_data" in operation:
data=argm[int(operation['arg_data'])]
elif "data" in operation:
data=operation['data']
else:
data=input(hexor(True).c("Data is empty : ","#ff0000"))
#xxx="hiii"
xxx=f"self.driver.find_element_by_{types}('{code}').get_attribute('{data}')"
hexor().c(text,"#299c52")
get_list.append(eval(xxx))
sleep(self.sleep_time)
#
except Exception as e:
try:
#
Expand All @@ -83,6 +103,7 @@ def run(self,goto,*argm):
pass
finally:
pass
return get_list
#end:
def end(self):
self.driver.close()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
hexor
asciitext
selenium
selenium
Binary file modified screenshot/screenshot_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from setuptools import setup,find_packages
setup(
name="imbot",
version="0.1.2",
version="0.1.3",
author="YasserBDJ96",
author_email="[email protected]",
description='''imbot for making a bot to control any website.''',
Expand Down Expand Up @@ -36,4 +36,4 @@
],
python_requires=">=3.x.x"
)
#}END.
#}END.
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.2
0.1.3

0 comments on commit 99e7b79

Please sign in to comment.