Im trying to make a bot using pyautogui. Im saving some important pixel with x , y location. There are some game cards on that locations. But I cant use them. Im using click funtion to click but i dont want to enter position everytime, i want to use same pixel location. Any help or idea appreciated.
from pyautogui import *
import pyautogui
import time
import keyboard
import random
import win32api, win32con
resimler = []
card1x = (833, 958, 1083)
card1y = (477, 622)
card2x =(809, 909, 1009, 1109)
card2y =(493, 609)
card3x =(833, 960, 1087)
card3y =(292, 464, 636, 808)
card4x =(809, 909, 1009, 1109)
card4y =(310, 470, 630, 790)
card5x =(809, 909, 1009, 1109)
card5y =(286, 418, 550, 682, 814)
cards =((card1x[0], card1y[0]),(card1x[1],card1y[0]),(card1x[2],card1y[0]),(card1x[0],card1y[1]),(card1x[1],card1y[1]),(card1x[2],card1y[1]),(card2x[0],card2y[0]),(card2x[1],card2y[0]),(card2x[2],card2y[0]),(card2x[3],card2y[0]),(card2x[0],card2y[1]),(card2x[1],card2y[1]),(card2x[2],card2y[1]),(card2x[3],card2y[1]))
When i print this, its printing
print(cards[5])
#(100,200)
but i need numbers for click funtion like this 100,200
Btw I will use like this
i=0
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
def list_islem(color):
global i
images.append(color)
if colorin images[:-1]:
print("bulundu")
click(cards[images.index(color)])
click(cards[i])
images.pop(images.index(color))
images.pop()
i-=1
print(images)
else:
print("bulunamadı")
print(images)
i+=1
when i use list_islem function i got this error
bulunamadı
[255]
bulundu
Traceback (most recent call last):
File "C:\Users\Gungor\Desktop\n11\bot.py", line 67, in <module>
list_islem(b)
File "C:\Users\Gungor\Desktop\n11\bot.py", line 44, in list_islem
click(cards[resimler.index(renk)])
TypeError: click() missing 1 required positional argument: 'y'
Think you're looking for the * tuple unpacking operator? Try the following
click(*cards[i]) # Using Tuple Unpacking
click(cards[i][0], cards[i][1]) # Which is equivalent to this
Related
from turtle import Turtle
my_turtle = Turtle()
my_turtle.color(40.0, 80.0, 120.0)
my_turtle.forward(50)
The code works well when I try to work with str such as .color("green") or .color("#285078"), but while I work with the 3 int I get this error:
Traceback (most recent call last):
File "E:\Python Projects\Practice\Day 18\main.py", line 4, in <module>
my_turtle.color(40.0, 80.0, 120.0)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 2217, in color
pcolor = self._colorstr(pcolor)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 2697, in _colorstr
return self.screen._colorstr(args)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 1167, in _colorstr
raise TurtleGraphicsError("bad color sequence: %s" % str(color))
turtle.TurtleGraphicsError: bad color sequence: (40.0, 80.0, 120.0)
Create a Screen object and set its colormode to 255 which on default was set to 1.0.
from turtle import Screen
my_screen = Screen()
my_screen.colormode(255)
Now pass the arguments of my_turtle.color() of integer datatype.
my_turtle.color(40, 80, 120)
Note: At the end of the program, add this line which lets you exit the window after a click, or else it closes automatically as soon it's opened.
my_screen.exitonclick()
when i ran the code below i got this error:
File "e:\pranil\python\doing shit with python\automating dino game.py", line 12, in
if auto.pixelMatchesColor(i,j, (83, 83, 83)):
File "C:\Users\Pranil.DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python38\lib\site-packages\pyscreeze__init__.py", line 559, in pixelMatchesColor
pix = pixel(x, y)
File "C:\Users\Pranil.DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python38\lib\site-packages\pyscreeze__init__.py", line 584, in pixel
return (r, g, b)
File "C:\Users\Pranil.DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python38\lib\contextlib.py", line 120, in exit
next(self.gen)
File "C:\Users\Pranil.DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python38\lib\site-packages\pyscreeze__init__.py", line 113, in __win32_openDC
raise WindowsError("windll.user32.ReleaseDC failed : return 0")
OSError: windll.user32.ReleaseDC failed : return 0
import pyautogui as auto
from PIL import Image, ImageColor
import time
import keyboard
auto.FAILSAFE = False
time.sleep(2)
# print(auto.position())
while True:
sshot = auto.screenshot()
for j in range(510, 514):
for i in range(316, 350):
if auto.pixelMatchesColor(i,j, (83, 83, 83)):
auto.press('up')
if keyboard.is_pressed('q'):
break
I'd suggest downgrading your python from 3.8 to 3.7, cause that solved it for me.
I am trying to get into writing code to scrape stock web pages, I came across this youtube video https://www.youtube.com/watch?v=2BrpKpWwT2A. When I copy and paste the following code (from the video)
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
style.use("ggplot")
start = dt.datetime(2015, 1, 1)
end = dt.datetime.now()
df = web.DataReader("TSLA", "yahoo", start, end)
print(df.head())
I still get the same error (Full traceback is too long to add here) but the last few lines say:
File "/anaconda3/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 363, in getpeercert
'subjectAltName': get_subj_alt_name(x509)
File "/anaconda3/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 213, in get_subj_alt_name
ext = cert.extensions.get_extension_for_class(
File "/anaconda3/lib/python3.6/site-packages/cryptography/utils.py", line 170, in inner
result = func(instance)
File "/anaconda3/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/x509.py", line 127, in extensions
self._backend, self._x509
File "/anaconda3/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/decode_asn1.py", line 252, in parse
value = handler(backend, ext_data)
File "/anaconda3/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/decode_asn1.py", line 438, in _decode_subject_alt_name
_decode_general_names_extension(backend, ext)
File "/anaconda3/lib/python3.6/site-packages/cryptography/x509/extensions.py", line 1262, in __init__
self._general_names = GeneralNames(general_names)
File "/anaconda3/lib/python3.6/site-packages/cryptography/x509/extensions.py", line 1217, in __init__
"Every item in the general_names list must be an "
TypeError: Every item in the general_names list must be an object conforming to the GeneralName interface
Any ideas as to what I could be doing wrong?
I tried the above code and got the following output:
I am trying to get Turtle-graphics to display a background image.
Here's my code:
import turtle
from turtle import *
from appJar import gui
...
turtle.setup(900,700) #windowsize
Ian = turtle.Turtle()
Ian.hideturtle()
Ian.screen.title("Arp Convertor")
Ian.screen.bgcolor("#4a4a54")
Ian.screen.bgpic('Backwslots2.gif')
Ian.speed(0)
Ian.penup() #dont draw
Ian.goto(-430,250) #where we'll start drawing
My image is the right size, exactly 900x700 in the current dir (same as my .py file). But the bgpic() line is giving me these errors.
> Exception in Tkinter callback Traceback (most recent call last):
> File
> "C:\Users\Ian\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py",
> line 1705, in __call__
> return self.func(*args) File "D:\Midipy\appJar\appjar.py", line 3574, in <lambda>
> return lambda *args: funcName(param) File "midipy.py", line 21, in openthefile
> convertthefile(btn) File "midipy.py", line 141, in convertthefile
> Ian.screen.bgpic('Backwslots2.gif') File "C:\Users\Ian\AppData\Local\Programs\Python\Python37-32\lib\turtle.py",
> line 1482, in bgpic
> self._setbgpic(self._bgpic, self._bgpics[picname]) File "C:\Users\Ian\AppData\Local\Programs\Python\Python37-32\lib\turtle.py",
> line 738, in _setbgpic
> self.cv.itemconfig(item, image=image)
Example:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
from reportlab.lib.pagesizes import letter
def testPdf():
doc = SimpleDocTemplate("testpdf.pdf",pagesize=letter,
rightMargin=72,leftMargin=72,
topMargin=72,bottomMargin=18)
elements = []
datas = []
for x in range(1,50):
datas.append(
[x,x+1]
)
t=Table(datas)
tTableStyle=[
('SPAN',(0,0),(0,37)),
]
t.setStyle(TableStyle(tTableStyle))
elements.append(t)
doc.build(elements)
if __name__ == '__main__':
testPdf()
this code runs success, because the table is in one page,if I set the "SPAN" to "(0,0),(0,38)" ,the error is:
reportlab.platypus.doctemplate.LayoutError: Flowable with cell(0,0) containing
'1'(46.24 x 702) too large on page 2 in frame 'normal'(456.0 x 690.0*) of template 'Later'
and if I set it bigger the error will be:
Traceback (most recent call last):
File "testpdf.py", line 26, in <module>
testPdf()
File "testpdf.py", line 23, in testPdf
doc.build(elements)
File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/doctemplate.py", line 1117, in build
BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/doctemplate.py", line 880, in build
self.handle_flowable(flowables)
File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/doctemplate.py", line 763, in handle_flowable
if frame.add(f, canv, trySplit=self.allowSplitting):
File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/frames.py", line 159, in _add
w, h = flowable.wrap(aW, h)
File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/tables.py", line 1113, in wrap
self._calc(availWidth, availHeight)
File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/tables.py", line 587, in _calc
self._calc_height(availHeight,availWidth,W=W)
File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/tables.py", line 553, in _calc_height
spanFixDim(H0,H,spanCons,lim=hmax)
File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/tables.py", line 205, in spanFixDim
t = sum([V[x]+M.get(x,0) for x in xrange(x0,x1)])
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
How can I deal with this?
The reason you're facing this problem is exactly what Gordon Worley commented above. There's no way to SPAN across page automatically as the algorithm implemented will be confused of the height and width calculated.
An approach to tackle this will be manually format/style your table per page using row/column coordinates. Sadly, even the replies in the reportlab suggest we do this manually.
I did split my tables manually and style them separately, which in my opinion is a very ugly approach. I'll look for other alternatives later.
For reference: https://bitbucket.org/ntj/reportlab_imko_table