├── .github └── workflows │ └── main.yaml ├── .gitignore ├── LICENSE ├── Pipfile ├── README.md ├── _Amazon.bat ├── __INSTALL (RUN FIRST).bat ├── _bbuy-evga.bat ├── _bbuy-fe.bat ├── _bbuy-gbyte.bat ├── _bbuy-msi.bat ├── _nvidiadotcom.bat ├── amazon_config.template_json ├── app.py ├── app.spec ├── autobuy_config.template_json ├── cli ├── __init__.py ├── cli.py └── utils.py ├── discord_config.template_json ├── evga_config.template_json ├── evga_pn.png ├── notifications ├── __init__.py ├── notifications.py └── providers │ ├── __init__.py │ ├── audio.py │ ├── discord.py │ ├── pavlok.py │ ├── slack.py │ ├── telegram.py │ └── twilio.py ├── notify.mp3 ├── nvidia-workflow.png ├── pavlok_config.template_json ├── slack_config.template_json ├── stores ├── __init__.py ├── amazon.py ├── bestbuy.py ├── evga.py ├── nvidia.py └── store_data │ └── nvidia_product_ids.json ├── telegram_config.template_json ├── twilio_config.template_json └── utils ├── __init__.py ├── http.py ├── json_utils.py ├── logger.py └── selenium_utils.py /.github/workflows/main.yaml: -------------------------------------------------------------------------------- 1 | name: autoblack 2 | on: [pull_request] 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v1 8 | - name: Set up Python 3.7 9 | uses: actions/setup-python@v1 10 | with: 11 | python-version: 3.7 12 | - name: Install Black 13 | run: pip install black 14 | - name: Run black --check . 15 | run: black --check . 16 | - name: If needed, commit black changes to the pull request 17 | if: failure() 18 | run: | 19 | black . 20 | git config --global user.name 'autoblack' 21 | git config --global user.email 'cclauss@users.noreply.github.com' 22 | git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY 23 | git checkout $GITHUB_HEAD_REF 24 | git commit -am "fixup: Format Python code with Black" 25 | git push 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | .idea/ 3 | build/ 4 | Pipfile.lock 5 | twilio_config.json 6 | discord_config.json 7 | telegram_config.json 8 | evga_config.json 9 | autobuy_config.json 10 | slack_config.json 11 | geckodriver.log 12 | .profile 13 | .profile-amz* 14 | *.log 15 | __pycache__/ 16 | *.py[cod] 17 | *.pkl 18 | .vscode/ 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | name = "pypi" 3 | url = "https://pypi.org/simple" 4 | verify_ssl = true 5 | 6 | [dev-packages] 7 | pyinstaller = "*" 8 | 9 | [packages] 10 | requests = "*" 11 | click = "*" 12 | selenium = "*" 13 | chromedriver-py = "==85.0.4183.87" 14 | furl = "*" 15 | twilio = "*" 16 | discord-webhook = "*" 17 | pycryptodome = "==3.9.8" 18 | questionary = "*" 19 | spinlog = "*" 20 | slackclient = "*" 21 | playsound = "*" 22 | prompt_toolkit = "*" 23 | aiohttp = "*" 24 | pyobjc = {version = "*", sys_platform = "== 'darwin'"} 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nvidia-bot 2 | 3 | [Installation](#Installation) | [Usage](#Usage) | [Discord](https://discord.gg/hQeUbRv) | [Troubleshooting](#Troubleshooting) 4 | 5 | ## Why??? 6 | 7 | I built this in response to the severe tech scalping situation that's happening right now. Almost every tech product that's coming 8 | out right now is being instantly brought out by scalping groups and then resold at at insane prices. $699 GPUs are being listed 9 | for $1700 on eBay, and these scalpers are buying 40 carts while normal consumers can't get a single one. Preorders for the PS5 are 10 | being resold for nearly $1000. My take on this is that if I release a bot that anyone can use, for free, then the number of items 11 | that scalpers can buy goes down and normal consumers can buy items for MSRP. If everyone is botting, then no one is botting. 12 | 13 | ## Installation 14 | 15 | For Raspberry Pi installation and setup, go [here](#Raspberry-Pi-Setup). 16 | 17 | This project uses [Pipenv](https://pypi.org/project/pipenv/) to manage dependencies. Hop in my [Discord](https://discord.gg/hQeUbRv) if you have ideas, need help or just want to tell me about how you got your new 3080. [TerryFrench](https://github.com/TerryFrench) has also created a youtube video detailing how to get this project running on Windows 10 as well. Huge thanks to him. 18 | 19 | [![Alt text](https://img.youtube.com/vi/TvOQubunx6o/0.jpg)](https://www.youtube.com/watch?v=TvOQubunx6o) 20 | 21 | 22 | ``` 23 | pip install pipenv 24 | pipenv shell 25 | pipenv install 26 | ``` 27 | 28 | Run it 29 | ``` 30 | python app.py 31 | 32 | Usage: app.py [OPTIONS] COMMAND [ARGS]... 33 | 34 | Options: 35 | --help Show this message and exit. 36 | 37 | Commands: 38 | amazon 39 | nvidia 40 | ``` 41 | 42 | ## Current Functionality 43 | 44 | | **Website** | **Auto Checkout** | **Open Cart Link** | **Test flag** | 45 | |:---:|:---:|:---:|:---:| 46 | | nvidia.com | |`✔`| | 47 | | amazon.com |`✔`| | | 48 | | bestbuy.com | |`✔`| | 49 | | evga.com |`✔` | |`✔`| 50 | 51 | 52 | ## Usage 53 | 54 | ### Amazon 55 | 56 | ***Warning***: This will buy every ASIN that is in stock the first time anything is in stock. So there is a possibility you can end up with multiple items. 57 | Thankfully Amazon.com has 1 click order canceling so its not a huge issue. We are working on a solution for this and price limits soon. 58 | 59 | **Amazon flags** 60 | ``` 61 | --no-image : prevents images from loading on amazon webdriver 62 | --test : This will not finish the checkout 63 | ``` 64 | 65 | Make a copy of `amazon_config.template_json` to `amazon_config.json`: 66 | ``` 67 | { 68 | "username": "", 69 | "password": "", 70 | "asin_list": ["B07JH53M4T","B08HR7SV3M"], 71 | "amazon_website": "amazon.com" 72 | } 73 | ``` 74 | Example usage: 75 | 76 | ``` 77 | python app.py amazon --test 78 | ... 79 | INFO: "2020-09-25 14:40:49,987 - Initializing notification handlers 80 | INFO: "2020-09-25 14:40:49,988 - Enabled Handlers: ['Audio', 'Twilio', 'Pavlok'] 81 | INFO: "2020-09-25 14:40:54,141 - Already logged in 82 | INFO: "2020-09-25 14:40:54,141 - Checking stock for items. 83 | INFO: "2020-09-25 14:40:54,614 - One or more items in stock! 84 | INFO: "2020-09-25 14:40:54,718 - Pavlok zaped 85 | INFO: "2020-09-25 14:40:54,848 - SMS Sent: SM68afc07b580f45d1b2527ec4b668f2d8 86 | INFO: "2020-09-25 14:40:58,771 - Clicking continue. 87 | INFO: "2020-09-25 14:41:03,816 - Waiting for Cart Page 88 | INFO: "2020-09-25 14:41:03,826 - On cart page. 89 | INFO: "2020-09-25 14:41:03,826 - clicking checkout. 90 | INFO: "2020-09-25 14:41:04,287 - Waiting for Place Your Order Page 91 | INFO: "2020-09-25 14:41:04,332 - Finishing checkout 92 | INFO: "2020-09-25 14:41:04,616 - Clicking Button: 93 | INFO: "2020-09-25 14:41:04,617 - Waiting for Order completed page. 94 | INFO: "2020-09-25 14:41:04,617 - This is a test, so we don't need to wait for the order completed page. 95 | INFO: "2020-09-25 14:41:04,617 - Order Placed. 96 | ``` 97 | 98 | ### Nvidia 99 | Will check stock and open an add to cart link in your browser and send notifications. 100 | 101 | **Nvidia flags** 102 | ``` 103 | --test : runs a test of the checkout process, without actually making the purchase 104 | --interval: How many seconds between each stock check (default: 5) 105 | ``` 106 | 107 | Example usage: 108 | ``` 109 | python app.py nvidia 110 | What GPU are you after?: 3080 111 | What locale shall we use? [en_us]: 112 | ... 113 | INFO: "2020-09-23 21:43:56,152 - We have 1 product IDs for NVIDIA GEFORCE RTX 3080 114 | INFO: "2020-09-23 21:43:56,153 - Product IDs: ['5438481700'] 115 | INFO: "2020-09-23 21:43:56,153 - Checking stock for 5438481700 at 5 second intervals. 116 | ``` 117 | 118 | Quick run: 119 | ``` 120 | python app.py nvidia --gpu 3080 --locale en_us 121 | ``` 122 | 123 | ## Best Buy 124 | This is fairly basic right now. Just login to the best buy website in your default browser and then run the command as follows: 125 | 126 | ``` 127 | python app.py bestbuy --sku [SKU] 128 | ``` 129 | 130 | Example: 131 | ``` 132 | python app.py bestbuy --sku 6429440 133 | ``` 134 | 135 | ## EVGA 136 | Make a copy of `evga_config.template_json` to `evga_config.json`: 137 | ``` 138 | { 139 | "username": "hari@", 140 | "password": "password!", 141 | "card_pn": "10G-P5-3895-KR", 142 | "card_series": "3080", 143 | "credit_card" : { 144 | "name": "Hari ", 145 | "number": "234234", 146 | "cvv": "123", 147 | "expiration_month": "12", 148 | "expiration_year": "2023" 149 | } 150 | } 151 | ``` 152 | 153 | Test run command (Uses old gpu list and then stops before finishing the order) 154 | `python app.py evga --test` 155 | 156 | Autobuy command: 157 | `python app.py evga --model [indentifier]` 158 | 159 | These are the series: "3090" or "3080" (any should work, untested) 160 | 161 | P/N numbers can be found in URLs or on product pages such as newegg. They look like this: 162 | 10G-P5-3895-KR 163 | 10G-P5-3881-KR 164 | 10G-P5-3885-KR 165 | ![EVGA PN Screenshot](evga_pn.png) 166 | 167 | if it doesn't load the correct page title (since the 3090 isn't listed yet), it will refresh every second until the correct page is loaded. 168 | 169 | 170 | ### Notifications 171 | This uses a notifications handler that will support multiple notification channels. 172 | 173 | #### Twilio 174 | To enable Twilio notifications, first go to https://www.twilio.com/ and create a free account and get a Twilio number. 175 | Then make a copy of `twilio_config.template_json` and name it `twilio_config.json`. If this file exists and the credentials are 176 | valid, the notification handler will send you an sms when it carts or purchases an item. 177 | ``` 178 | { 179 | "account_sid": "ACCOUNT_SID", 180 | "auth_token": "AUTH_TOKEN", 181 | "from": "YOUR TWILIO NUMBER", 182 | "to": "THE NUMBER YOU WANT TO SEND SMS TO" 183 | } 184 | ``` 185 | 186 | #### Discord 187 | To enable Discord notifications, first get your wehbook url. Use the directions [here](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) to get the webhook url. 188 | Make a copy of the `discord_config.template_json` file and name it `discord_config.json` and place the webhook url here. 189 | Optionally a [user id](https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-) can be added to ping someone (like yourself). 190 | ``` 191 | { 192 | "webhook_url": "Discord webhook url here", 193 | "user_id": "Optional user id to ping here" 194 | } 195 | ``` 196 | 197 | #### Telegram 198 | To enable Telegram notifications, you have to create a new bot and get your chat id. Use the directions [here](https://medium.com/@ManHay_Hong/how-to-create-a-telegram-bot-and-send-messages-with-python-4cf314d9fa3e) (Creating your bot and Getting your Chat id sections). 199 | 200 | Make a copy of the `telegram_config.template_json` file and name it `telegram_config.json` and place your `BOT_TOKEN` and `BOT_CHAT_ID` values here. 201 | ``` 202 | { 203 | "BOT_TOKEN" : "1234567890:abcdefghijklmnopqrstuvwxyz", 204 | "BOT_CHAT_ID" : "111222333" 205 | } 206 | ``` 207 | 208 | It is possible to notify multiple users at once. Just add a list as the `BOT_CHAT_ID` value: 209 | 210 | ``` 211 | { 212 | "BOT_TOKEN" : "1234567890:abcdefghijklmnopqrstuvwxyz", 213 | "BOT_CHAT_ID" : ["111222333", "444555666"] 214 | } 215 | ``` 216 | 217 | #### Pavlok 218 | To enable shock notifications to your [Pavlok Shockwatch](https://www.amazon.com/Pavlok-PAV2-PERIMETER-BLACK-2/dp/B01N8VJX8P?), 219 | store the url from the pavlok app in the ```pavlok_config.json``` file, you can copy the template from ```pavlok_config.template_json```. 220 | 221 | **WARNING:** This feature does not currently support adjusting the intensity, it will always be max (255). 222 | ``` 223 | { 224 | "base_url": "url goes here" 225 | } 226 | ``` 227 | 228 | 229 | 230 | ## Troubleshooting 231 | 232 | I suggest joining the #Support channel in [Discord](https://discord.gg/hQeUbRv) for personal assistance if these common fixes don't help. 233 | 234 | **Error: ```selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary```** 235 | The issue is that chrome is not installed in the expected location. See [Selenium Wiki](https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver#requirements) and the section on [overriding the Chrome binary location .](https://sites.google.com/a/chromium.org/chromedriver/capabilities#TOC-Using-a-Chrome-executable-in-a-non-standard-location) 236 | 237 | The easy fix for this is to add an option where selenium is used (amazon.py) 238 | ``` 239 | chrome_options.binary_location="C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe" 240 | ``` 241 | 242 | **Error: ```selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 85```** 243 | 244 | You are not running the proper version of Chrome this requires. As of this update, the current version is Chrome 85. Check your version by going to ```chrome://version/``` in your browser. We are going to be targeting the current stable build of chrome. If you are behind, please update, if you are on a beta or canary branch, you'll have to build your own version of chromedriver-py. 245 | 246 | ## Raspberry-Pi-Setup 247 | 248 | 1. Prereqs and Setup 249 | ``` 250 | sudo apt update 251 | sudo apt upgrade 252 | sudo apt install chromium-chromedriver 253 | git clone https://github.com/Hari-Nagarajan/nvidia-bot 254 | cd nvidia-bot/ 255 | pip3 install pipenv 256 | export PATH=$PATH:/home//.local/bin 257 | pipenv shell 258 | pipenv install 259 | ``` 260 | 2. Leave this Terminal window open. 261 | 262 | 3. Open the following file in a text editor: 263 | ``` 264 | /home//.local/share/virtualenvs/nvidia-bot-/lib/python3.7/site-packages/selenium/webdriver/common/service.py 265 | ``` 266 | 4. Edit line 38 from `self.path = executable` to `self.path = "chromedriver"`, then save and close the file. 267 | 268 | 269 | 5. Back in Terminal... 270 | ``` 271 | python app.py 272 | ``` 273 | 274 | 6. Follow [Usage](#Usage) to configure the bot as needed. 275 | 276 | ## Attribution 277 | 278 | Notification sound from https://notificationsounds.com. 279 | -------------------------------------------------------------------------------- /_Amazon.bat: -------------------------------------------------------------------------------- 1 | pipenv run python app.py amazon -------------------------------------------------------------------------------- /__INSTALL (RUN FIRST).bat: -------------------------------------------------------------------------------- 1 | @ehcho on 2 | pip install pipenv 3 | pause 4 | pipenv install 5 | 6 | 7 | 8 | 9 | pause ------===== Installed! You can now use the launchers!=====------ 10 | exit -------------------------------------------------------------------------------- /_bbuy-evga.bat: -------------------------------------------------------------------------------- 1 | pipenv run python app.py bestbuy --sku 6432399 -------------------------------------------------------------------------------- /_bbuy-fe.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanotero/nvidia-bot/478c047345bb1bed317a5c266d3905132f96cf9f/_bbuy-fe.bat -------------------------------------------------------------------------------- /_bbuy-gbyte.bat: -------------------------------------------------------------------------------- 1 | pipenv run python app.py bestbuy --sku 6430621 -------------------------------------------------------------------------------- /_bbuy-msi.bat: -------------------------------------------------------------------------------- 1 | pipenv run python app.py bestbuy --sku 6432399 -------------------------------------------------------------------------------- /_nvidiadotcom.bat: -------------------------------------------------------------------------------- 1 | pipenv install 2 | 3 | pipenv run python app.py nvidia 4 | -------------------------------------------------------------------------------- /amazon_config.template_json: -------------------------------------------------------------------------------- 1 | { 2 | "username": "", 3 | "password": "", 4 | "asin_list": ["B07JH53M4T","B08HR7SV3M"], 5 | "amazon_website": "amazon.co.uk" 6 | } -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from cli import cli 2 | 3 | 4 | if __name__ == "__main__": 5 | cli.main() 6 | -------------------------------------------------------------------------------- /app.spec: -------------------------------------------------------------------------------- 1 | # -*- mode: python ; coding: utf-8 -*- 2 | 3 | block_cipher = None 4 | 5 | 6 | a = Analysis(['app.py'], 7 | pathex=['C:\\Users\\hari\\PycharmProjects\\nvidia-bot'], 8 | binaries=[], 9 | datas=[], 10 | hiddenimports=[], 11 | hookspath=[], 12 | runtime_hooks=[], 13 | excludes=[], 14 | win_no_prefer_redirects=False, 15 | win_private_assemblies=False, 16 | cipher=block_cipher, 17 | noarchive=False) 18 | pyz = PYZ(a.pure, a.zipped_data, 19 | cipher=block_cipher) 20 | exe = EXE(pyz, 21 | a.scripts, 22 | a.binaries, 23 | a.zipfiles, 24 | a.datas, 25 | [], 26 | name='app', 27 | debug=False, 28 | bootloader_ignore_signals=False, 29 | strip=False, 30 | upx=True, 31 | upx_exclude=[], 32 | runtime_tmpdir=None, 33 | console=True ) 34 | -------------------------------------------------------------------------------- /autobuy_config.template_json: -------------------------------------------------------------------------------- 1 | { 2 | "NVIDIA_LOGIN": "fuckthesc@lpers.com", 3 | "NVIDIA_PASSWORD": "12345", 4 | "FULL_AUTOBUY":false, 5 | "CVV":"101", 6 | "BYPASS_ADDRESS_SUGGESTION":false, 7 | "INTERVAL": "5" 8 | } -------------------------------------------------------------------------------- /cli/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanotero/nvidia-bot/478c047345bb1bed317a5c266d3905132f96cf9f/cli/__init__.py -------------------------------------------------------------------------------- /cli/cli.py: -------------------------------------------------------------------------------- 1 | import click 2 | 3 | from cli.utils import QuestionaryOption 4 | from stores.amazon import Amazon 5 | from stores.bestbuy import BestBuyHandler 6 | from stores.evga import Evga 7 | from stores.nvidia import NvidiaBuyer, GPU_DISPLAY_NAMES, ACCEPTED_LOCALES 8 | from utils import selenium_utils 9 | 10 | 11 | @click.group() 12 | def main(): 13 | pass 14 | 15 | 16 | @click.command() 17 | @click.option( 18 | "--gpu", 19 | type=click.Choice(GPU_DISPLAY_NAMES, case_sensitive=False), 20 | prompt="What GPU are you after?", 21 | cls=QuestionaryOption, 22 | ) 23 | @click.option( 24 | "--locale", 25 | type=click.Choice(ACCEPTED_LOCALES, case_sensitive=False), 26 | prompt="What locale shall we use?", 27 | cls=QuestionaryOption, 28 | ) 29 | @click.option("--test", is_flag=True) 30 | @click.option("--interval", type=int, default=5) 31 | def nvidia(gpu, locale, test, interval): 32 | nv = NvidiaBuyer(gpu, locale, test, interval) 33 | nv.run_items() 34 | 35 | 36 | @click.command() 37 | @click.option("--no-image", is_flag=True) 38 | @click.option("--headless", is_flag=True) 39 | @click.option("--test", is_flag=True) 40 | def amazon(no_image, headless, test): 41 | if no_image: 42 | selenium_utils.no_amazon_image() 43 | amzn_obj = Amazon(headless=headless) 44 | amzn_obj.run_item(test=test) 45 | 46 | 47 | @click.command() 48 | @click.option("--sku", type=str, required=True) 49 | @click.option("--headless", is_flag=True) 50 | def bestbuy(sku, headless): 51 | bb = BestBuyHandler(sku, headless) 52 | bb.run_item() 53 | 54 | 55 | @click.command() 56 | @click.option("--test", is_flag=True) 57 | @click.option("--headless", is_flag=True) 58 | def evga(test, headless): 59 | ev = Evga(headless) 60 | ev.buy(test=test) 61 | 62 | 63 | main.add_command(nvidia) 64 | main.add_command(amazon) 65 | main.add_command(bestbuy) 66 | main.add_command(evga) 67 | -------------------------------------------------------------------------------- /cli/utils.py: -------------------------------------------------------------------------------- 1 | import click 2 | import questionary 3 | 4 | 5 | class QuestionaryOption(click.Option): 6 | def __init__(self, param_decls=None, **attrs): 7 | click.Option.__init__(self, param_decls, **attrs) 8 | 9 | def prompt_for_value(self, ctx): 10 | return questionary.select(self.prompt, choices=self.type.choices).unsafe_ask() 11 | -------------------------------------------------------------------------------- /discord_config.template_json: -------------------------------------------------------------------------------- 1 | { 2 | "webhook_url": "Discord webhook url here", 3 | "user_id": "Optional user id to ping here" 4 | } -------------------------------------------------------------------------------- /evga_config.template_json: -------------------------------------------------------------------------------- 1 | { 2 | "username": "", 3 | "password": "", 4 | "card_pn": "", 5 | "card_series": "", 6 | "credit_card" : { 7 | "name": "", 8 | "number": "", 9 | "cvv": "", 10 | "expiration_month": "", 11 | "expiration_year": "" 12 | } 13 | } -------------------------------------------------------------------------------- /evga_pn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanotero/nvidia-bot/478c047345bb1bed317a5c266d3905132f96cf9f/evga_pn.png -------------------------------------------------------------------------------- /notifications/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanotero/nvidia-bot/478c047345bb1bed317a5c266d3905132f96cf9f/notifications/__init__.py -------------------------------------------------------------------------------- /notifications/notifications.py: -------------------------------------------------------------------------------- 1 | from concurrent.futures import ThreadPoolExecutor 2 | 3 | from notifications.providers.audio import AudioHandler 4 | from notifications.providers.discord import DiscordHandler 5 | from notifications.providers.pavlok import PavlokHandler 6 | from notifications.providers.slack import SlackHandler 7 | from notifications.providers.telegram import TelegramHandler 8 | from notifications.providers.twilio import TwilioHandler 9 | from utils.logger import log 10 | 11 | 12 | class NotificationHandler: 13 | def __init__(self): 14 | log.info("Initializing notification handlers") 15 | self.audio_handler = AudioHandler() 16 | self.twilio_handler = TwilioHandler() 17 | self.discord_handler = DiscordHandler() 18 | self.telegram_handler = TelegramHandler() 19 | self.slack_handler = SlackHandler() 20 | self.pavlok_handler = PavlokHandler() 21 | log.info(f"Enabled Handlers: {self.get_enabled_handlers()}") 22 | 23 | def get_enabled_handlers(self): 24 | enabled_handlers = [] 25 | if self.audio_handler.enabled: 26 | enabled_handlers.append("Audio") 27 | if self.twilio_handler.enabled: 28 | enabled_handlers.append("Twilio") 29 | if self.discord_handler.enabled: 30 | enabled_handlers.append("Discord") 31 | if self.telegram_handler.enabled: 32 | enabled_handlers.append("Telegram") 33 | if self.slack_handler.enabled: 34 | enabled_handlers.append("Slack") 35 | if self.pavlok_handler.enabled: 36 | enabled_handlers.append("Pavlok") 37 | return enabled_handlers 38 | 39 | def send_notification(self, message): 40 | with ThreadPoolExecutor( 41 | max_workers=len(self.get_enabled_handlers()) 42 | ) as executor: 43 | if self.audio_handler.enabled: 44 | executor.submit(self.audio_handler.play) 45 | if self.twilio_handler.enabled: 46 | executor.submit(self.twilio_handler.send, message) 47 | if self.discord_handler.enabled: 48 | executor.submit(self.discord_handler.send, message) 49 | if self.telegram_handler.enabled: 50 | executor.submit(self.telegram_handler.send, message) 51 | if self.slack_handler.enabled: 52 | executor.submit(self.slack_handler.send, message) 53 | if self.pavlok_handler.enabled: 54 | executor.submit(self.pavlok_handler.zap) 55 | -------------------------------------------------------------------------------- /notifications/providers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanotero/nvidia-bot/478c047345bb1bed317a5c266d3905132f96cf9f/notifications/providers/__init__.py -------------------------------------------------------------------------------- /notifications/providers/audio.py: -------------------------------------------------------------------------------- 1 | from os import path 2 | 3 | from playsound import playsound 4 | 5 | from utils.logger import log 6 | 7 | PROJECT_DIR = path.abspath(path.dirname(path.dirname(__file__))) 8 | NOTIFICATION_SOUND_PATH = "notify.mp3" 9 | 10 | 11 | class AudioHandler: 12 | enabled = False 13 | 14 | def __init__(self): 15 | log.debug("Initializing local audio handler") 16 | 17 | if path.exists(NOTIFICATION_SOUND_PATH): 18 | self.enabled = True 19 | else: 20 | log.debug("No notificaiton sound file found.") 21 | 22 | def play(self): 23 | try: 24 | playsound(NOTIFICATION_SOUND_PATH, True) 25 | except Exception as e: 26 | log.error(e) 27 | log.warn( 28 | "Error playing notification sound. Disabling local audio notifications." 29 | ) 30 | self.enabled = False 31 | -------------------------------------------------------------------------------- /notifications/providers/discord.py: -------------------------------------------------------------------------------- 1 | import json 2 | from os import path 3 | 4 | from discord_webhook import DiscordWebhook 5 | 6 | from utils.logger import log 7 | 8 | DISCORD_CONFIG_PATH = "discord_config.json" 9 | DISCORD_CONFIG_KEYS = ["webhook_url"] 10 | 11 | 12 | class DiscordHandler: 13 | enabled = False 14 | 15 | def __init__(self): 16 | log.debug("Initializing discord handler") 17 | 18 | if path.exists(DISCORD_CONFIG_PATH): 19 | with open(DISCORD_CONFIG_PATH) as json_file: 20 | self.config = json.load(json_file) 21 | if self.config["webhook_url"]: 22 | self.webhook_url = self.config["webhook_url"] 23 | self.user_id = self.config.get("user_id", "N/A") 24 | self.enabled = True 25 | else: 26 | log.debug("No Discord creds found.") 27 | 28 | def send(self, message_body): 29 | try: 30 | message = ( 31 | f"<@{self.user_id}> {message_body}" 32 | if self.user_id.isdigit() 33 | else message_body 34 | ) 35 | web_hook = DiscordWebhook(url=self.webhook_url, content=message) 36 | response = web_hook.execute() 37 | log.info(f"Discord hook status: {response.status_code}") 38 | except Exception as e: 39 | log.error(e) 40 | log.warn("Discord send message failed. Disabling Discord notifications.") 41 | self.enabled = False 42 | -------------------------------------------------------------------------------- /notifications/providers/pavlok.py: -------------------------------------------------------------------------------- 1 | import json 2 | from os import path 3 | 4 | import requests 5 | 6 | from utils.logger import log 7 | 8 | PAVLOK_CONFIG_PATH = "pavlok_config.json" 9 | PAVLOK_CONFIG_KEYS = ["base_url"] 10 | 11 | 12 | ZAP_URL = "/zap/255" 13 | 14 | 15 | class PavlokHandler: 16 | enabled = False 17 | 18 | def __init__(self): 19 | log.debug("Initializing pavlok handler") 20 | 21 | if path.exists(PAVLOK_CONFIG_PATH): 22 | with open(PAVLOK_CONFIG_PATH) as json_file: 23 | self.config = json.load(json_file) 24 | if self.config["base_url"]: 25 | self.base_url = self.config["base_url"] 26 | self.enabled = True 27 | else: 28 | log.debug("No pavlok config found.") 29 | 30 | def zap(self): 31 | try: 32 | response = requests.get(self.base_url + ZAP_URL) 33 | log.info(f"Pavlok zaped") 34 | except Exception as e: 35 | log.error(e) 36 | log.warn("Pavlok failed to zap..") 37 | self.enabled = False 38 | -------------------------------------------------------------------------------- /notifications/providers/slack.py: -------------------------------------------------------------------------------- 1 | import json 2 | from os import path 3 | 4 | from slack import WebClient 5 | 6 | from slack.errors import SlackApiError 7 | 8 | from utils.logger import log 9 | 10 | 11 | SLACK_CONFIG_PATH = "slack_config.json" 12 | SLACK_CONFIG_KEYS = ["slack_user", "slack_channel", "slack_token"] 13 | 14 | 15 | class SlackHandler: 16 | 17 | enabled = False 18 | 19 | def __init__(self): 20 | log.debug("Initializing slack handler") 21 | 22 | if path.exists(SLACK_CONFIG_PATH): 23 | with open(SLACK_CONFIG_PATH) as json_file: 24 | self.config = json.load(json_file) 25 | if self.has_valid_creds(): 26 | self.enabled = True 27 | try: 28 | self.client = WebClient(token=self.config["slack_token"]) 29 | except Exception as e: 30 | log.warn( 31 | "Slack client creation failed. Disabling Slack notifications." 32 | ) 33 | self.enabled = False 34 | else: 35 | log.debug("No Slack creds found.") 36 | 37 | def has_valid_creds(self): 38 | if all(item in self.config.keys() for item in SLACK_CONFIG_KEYS): 39 | return True 40 | else: 41 | return False 42 | 43 | def send(self, message_body): 44 | try: 45 | response = self.client.chat_postMessage( 46 | channel=self.config["slack_channel"], text=message_body 47 | ) 48 | 49 | log.info(f"Slack message sent: {response.status_code}") 50 | except SlackApiError as e: 51 | log.error(e) 52 | log.warn("Slack send message failed. Disabling Slack notifications.") 53 | self.enabled = False 54 | -------------------------------------------------------------------------------- /notifications/providers/telegram.py: -------------------------------------------------------------------------------- 1 | import json 2 | from os import path 3 | from urllib.parse import quote 4 | 5 | import requests 6 | 7 | from utils.logger import log 8 | 9 | TELEGRAM_CONFIG_PATH = "telegram_config.json" 10 | TELEGRAM_CONFIG_KEYS = ["BOT_TOKEN", "BOT_CHAT_ID"] 11 | 12 | 13 | class TelegramHandler: 14 | enabled = False 15 | 16 | def __init__(self): 17 | log.debug("Initializing telegram handler") 18 | 19 | if path.exists(TELEGRAM_CONFIG_PATH): 20 | with open(TELEGRAM_CONFIG_PATH) as json_file: 21 | self.config = json.load(json_file) 22 | if self.config["BOT_TOKEN"] and self.config["BOT_CHAT_ID"]: 23 | self.bot_token = self.config["BOT_TOKEN"] 24 | self.bot_chat_id = self.config["BOT_CHAT_ID"] 25 | if not isinstance(self.bot_chat_id, list): 26 | self.bot_chat_id = [self.bot_chat_id] 27 | self.enabled = True 28 | else: 29 | log.debug("No Telegram config found.") 30 | 31 | def send(self, message_body): 32 | try: 33 | for chat_id in self.bot_chat_id: 34 | requests.get( 35 | f"https://api.telegram.org/bot{self.bot_token}/sendMessage?" 36 | f"chat_id={chat_id}&text={quote(message_body)}" 37 | ) 38 | except Exception as e: 39 | log.error(e) 40 | log.warn("Telegram send message failed. Disabling Telegram notifications.") 41 | self.enabled = False 42 | -------------------------------------------------------------------------------- /notifications/providers/twilio.py: -------------------------------------------------------------------------------- 1 | import json 2 | from os import path 3 | 4 | from twilio.rest import Client 5 | 6 | from utils.logger import log 7 | 8 | TWILIO_CONFIG_PATH = "twilio_config.json" 9 | TWILIO_CONFIG_KEYS = ["account_sid", "auth_token", "from", "to"] 10 | 11 | 12 | class TwilioHandler: 13 | 14 | enabled = False 15 | 16 | def __init__(self): 17 | log.debug("Initializing twilio handler") 18 | 19 | if path.exists(TWILIO_CONFIG_PATH): 20 | with open(TWILIO_CONFIG_PATH) as json_file: 21 | self.config = json.load(json_file) 22 | if self.has_valid_creds(): 23 | self.enabled = True 24 | try: 25 | self.client = Client( 26 | self.config["account_sid"], self.config["auth_token"] 27 | ) 28 | except Exception as e: 29 | log.warn( 30 | "Twilio client creation failed. Disabling Twilio notifications." 31 | ) 32 | self.enabled = False 33 | else: 34 | log.debug("No Twilio creds found.") 35 | 36 | def has_valid_creds(self): 37 | if all(item in self.config.keys() for item in TWILIO_CONFIG_KEYS): 38 | return True 39 | else: 40 | return False 41 | 42 | def send(self, message_body): 43 | try: 44 | message = self.client.messages.create( 45 | from_=self.config["from"], body=message_body, to=self.config["to"] 46 | ) 47 | log.info("SMS Sent: " + message.sid) 48 | except Exception as e: 49 | log.error(e) 50 | log.warn("Twilio send message failed. Disabling Twilio notifications.") 51 | self.enabled = False 52 | -------------------------------------------------------------------------------- /notify.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanotero/nvidia-bot/478c047345bb1bed317a5c266d3905132f96cf9f/notify.mp3 -------------------------------------------------------------------------------- /nvidia-workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanotero/nvidia-bot/478c047345bb1bed317a5c266d3905132f96cf9f/nvidia-workflow.png -------------------------------------------------------------------------------- /pavlok_config.template_json: -------------------------------------------------------------------------------- 1 | { 2 | "base_url": "url goes here" 3 | } -------------------------------------------------------------------------------- /slack_config.template_json: -------------------------------------------------------------------------------- 1 | { 2 | "slack_user": "Notify Bot", 3 | "slack_channel": "ReportToThisSlackChannel", 4 | "slack_token": "ENTER-YOUR-SLACK-TOKEN-HERE" 5 | } -------------------------------------------------------------------------------- /stores/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanotero/nvidia-bot/478c047345bb1bed317a5c266d3905132f96cf9f/stores/__init__.py -------------------------------------------------------------------------------- /stores/amazon.py: -------------------------------------------------------------------------------- 1 | import json 2 | import secrets 3 | import time 4 | from os import path 5 | 6 | from chromedriver_py import binary_path # this will get you the path variable 7 | from furl import furl 8 | from selenium import webdriver 9 | from selenium.common.exceptions import NoSuchElementException 10 | from selenium.webdriver.common.keys import Keys 11 | from selenium.webdriver.support.ui import WebDriverWait 12 | 13 | from notifications.notifications import NotificationHandler 14 | from utils import selenium_utils 15 | from utils.json_utils import InvalidAutoBuyConfigException 16 | from utils.logger import log 17 | from utils.selenium_utils import options, enable_headless, wait_for_element 18 | 19 | AMAZON_URLS = { 20 | "BASE_URL": "https://www.{}/", 21 | "CART_URL": "https://www.{}/gp/aws/cart/add.html", 22 | } 23 | 24 | AUTOBUY_CONFIG_PATH = "amazon_config.json" 25 | 26 | SIGN_IN_TITLES = ["Amazon Sign In", "Amazon Sign-In", "Amazon Anmelden"] 27 | SHOPING_CART_TITLES = [ 28 | "Amazon.com Shopping Cart", 29 | "Amazon.co.uk Shopping Basket", 30 | "Amazon.de Basket", 31 | ] 32 | CHECKOUT_TITLES = [ 33 | "Amazon.com Checkout", 34 | "Place Your Order - Amazon.co.uk Checkout", 35 | "Place Your Order - Amazon.de Checkout", 36 | "Place Your Order - Amazon.com Checkout", 37 | "Place Your Order - Amazon.com", 38 | ] 39 | ORDER_COMPLETE_TITLES = ["Amazon.com Thanks You", "Thank you"] 40 | ADD_TO_CART_TITLES = [ 41 | "Amazon.com: Please Confirm Your Action", 42 | "Amazon.de: Bitte bestätigen Sie Ihre Aktion", 43 | "Amazon.de: Please Confirm Your Action", 44 | ] 45 | 46 | 47 | class Amazon: 48 | def __init__(self, headless=False): 49 | self.notification_handler = NotificationHandler() 50 | if headless: 51 | enable_headless() 52 | options.add_argument(f"user-data-dir=.profile-amz") 53 | self.driver = webdriver.Chrome(executable_path=binary_path, options=options) 54 | self.wait = WebDriverWait(self.driver, 10) 55 | if path.exists(AUTOBUY_CONFIG_PATH): 56 | with open(AUTOBUY_CONFIG_PATH) as json_file: 57 | try: 58 | config = json.load(json_file) 59 | self.username = config["username"] 60 | self.password = config["password"] 61 | self.asin_list = config["asin_list"] 62 | self.amazon_website = config.get("amazon_website", "amazon.com") 63 | assert isinstance(self.asin_list, list) 64 | except Exception: 65 | raise InvalidAutoBuyConfigException( 66 | "amazon_config.json file not formatted properly." 67 | ) 68 | else: 69 | raise InvalidAutoBuyConfigException("Missing amazon_config.json file.") 70 | 71 | for key in AMAZON_URLS.keys(): 72 | AMAZON_URLS[key] = AMAZON_URLS[key].format(self.amazon_website) 73 | print(AMAZON_URLS) 74 | self.driver.get(AMAZON_URLS["BASE_URL"]) 75 | if self.is_logged_in(): 76 | log.info("Already logged in") 77 | else: 78 | log.info("Lets log in.") 79 | selenium_utils.button_click_using_xpath( 80 | self.driver, '//*[@id="nav-link-accountList"]/div/span' 81 | ) 82 | selenium_utils.wait_for_any_title(self.driver, SIGN_IN_TITLES) 83 | self.login() 84 | log.info("Waiting 15 seconds.") 85 | time.sleep( 86 | 15 87 | ) # We can remove this once I get more info on the phone verification page. 88 | 89 | def is_logged_in(self): 90 | try: 91 | text = wait_for_element(self.driver, "nav-link-accountList").text 92 | return "Hello, Sign in" not in text 93 | except Exception: 94 | return False 95 | 96 | def login(self): 97 | 98 | try: 99 | log.info("Email") 100 | self.driver.find_element_by_xpath('//*[@id="ap_email"]').send_keys( 101 | self.username + Keys.RETURN 102 | ) 103 | except: 104 | log.info("Email not needed.") 105 | pass 106 | 107 | log.info("Password") 108 | self.driver.find_element_by_xpath('//input[@name="rememberMe"]').click() 109 | self.driver.find_element_by_xpath('//*[@id="ap_password"]').send_keys( 110 | self.password + Keys.RETURN 111 | ) 112 | 113 | log.info(f"Logged in as {self.username}") 114 | 115 | def run_item(self, delay=3, test=False): 116 | log.info("Checking stock for items.") 117 | while not self.something_in_stock(): 118 | time.sleep(delay) 119 | self.notification_handler.send_notification( 120 | "Your items on Amazon.com were found!" 121 | ) 122 | self.checkout(test=test) 123 | 124 | def something_in_stock(self): 125 | params = {"anticache": str(secrets.token_urlsafe(32))} 126 | 127 | for x in range(len(self.asin_list)): 128 | params[f"ASIN.{x + 1}"] = self.asin_list[x] 129 | params[f"Quantity.{x + 1}"] = 1 130 | 131 | f = furl(AMAZON_URLS["CART_URL"]) 132 | f.set(params) 133 | self.driver.get(f.url) 134 | selenium_utils.wait_for_any_title(self.driver, ADD_TO_CART_TITLES) 135 | if self.driver.find_elements_by_xpath('//td[@class="price item-row"]'): 136 | log.info("One or more items in stock!") 137 | 138 | return True 139 | else: 140 | return False 141 | 142 | def wait_for_cart_page(self): 143 | selenium_utils.wait_for_any_title(self.driver, SHOPING_CART_TITLES) 144 | log.info("On cart page.") 145 | 146 | def wait_for_pyo_page(self): 147 | selenium_utils.wait_for_any_title(self.driver, CHECKOUT_TITLES + SIGN_IN_TITLES) 148 | 149 | if self.driver.title in SIGN_IN_TITLES: 150 | log.info("Need to sign in again") 151 | self.login() 152 | 153 | def finalize_order_button(self, test, retry=0): 154 | button_xpaths = [ 155 | '//*[@id="bottomSubmitOrderButtonId"]/span/input', 156 | '//*[@id="placeYourOrder"]/span/input', 157 | '//*[@id="submitOrderButtonId"]/span/input', 158 | '//input[@name="placeYourOrder1"]', 159 | ] 160 | button = None 161 | for button_xpath in button_xpaths: 162 | try: 163 | if ( 164 | self.driver.find_element_by_xpath(button_xpath).is_displayed() 165 | and self.driver.find_element_by_xpath(button_xpath).is_enabled() 166 | ): 167 | button = self.driver.find_element_by_xpath(button_xpath) 168 | except NoSuchElementException: 169 | log.debug(f"{button_xpath}, lets try a different one.") 170 | 171 | if button: 172 | log.info(f"Clicking Button: {button}") 173 | if not test: 174 | button.click() 175 | return 176 | else: 177 | if retry < 3: 178 | log.info("Couldn't find button. Lets retry in a sec.") 179 | time.sleep(5) 180 | self.finalize_order_button(test, retry + 1) 181 | else: 182 | log.info( 183 | "Couldn't find button after 3 retries. Open a GH issue for this." 184 | ) 185 | 186 | def wait_for_order_completed(self, test): 187 | if not test: 188 | selenium_utils.wait_for_any_title(self.driver, ORDER_COMPLETE_TITLES) 189 | else: 190 | log.info( 191 | "This is a test, so we don't need to wait for the order completed page." 192 | ) 193 | 194 | def checkout(self, test): 195 | log.info("Clicking continue.") 196 | self.driver.find_element_by_xpath('//input[@value="add"]').click() 197 | 198 | log.info("Waiting for Cart Page") 199 | self.wait_for_cart_page() 200 | 201 | log.info("clicking checkout.") 202 | self.driver.find_element_by_xpath( 203 | '//*[@id="sc-buy-box-ptc-button"]/span/input' 204 | ).click() 205 | 206 | log.info("Waiting for Place Your Order Page") 207 | self.wait_for_pyo_page() 208 | 209 | log.info("Finishing checkout") 210 | self.finalize_order_button(test) 211 | 212 | log.info("Waiting for Order completed page.") 213 | self.wait_for_order_completed(test) 214 | 215 | log.info("Order Placed.") 216 | -------------------------------------------------------------------------------- /stores/bestbuy.py: -------------------------------------------------------------------------------- 1 | import json 2 | import webbrowser 3 | from time import sleep 4 | 5 | from chromedriver_py import binary_path # this will get you the path variable 6 | from selenium import webdriver 7 | from selenium.webdriver.chrome.options import Options 8 | from selenium.webdriver.support.ui import WebDriverWait 9 | 10 | try: 11 | from Crypto.PublicKey import RSA 12 | from Crypto.Cipher import PKCS1_OAEP 13 | except: 14 | from Cryptodome.PublicKey import RSA 15 | from Cryptodome.Cipher import PKCS1_OAEP 16 | 17 | import requests 18 | from requests.adapters import HTTPAdapter 19 | from requests.packages.urllib3.util.retry import Retry 20 | 21 | from notifications.notifications import NotificationHandler 22 | from utils.json_utils import find_values 23 | from utils.logger import log 24 | from utils.selenium_utils import enable_headless 25 | 26 | BEST_BUY_PDP_URL = "https://api.bestbuy.com/click/5592e2b895800000/{sku}/pdp" 27 | BEST_BUY_CART_URL = "https://api.bestbuy.com/click/5592e2b895800000/{sku}/cart" 28 | 29 | BEST_BUY_ADD_TO_CART_API_URL = "https://www.bestbuy.com/cart/api/v1/addToCart" 30 | BEST_BUY_CHECKOUT_URL = "https://www.bestbuy.com/checkout/c/orders/{order_id}/" 31 | 32 | DEFAULT_HEADERS = { 33 | "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", 34 | "accept-encoding": "gzip, deflate, br", 35 | "accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7", 36 | "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36", 37 | "origin": "https://www.bestbuy.com", 38 | } 39 | 40 | options = Options() 41 | options.page_load_strategy = "eager" 42 | options.add_experimental_option("excludeSwitches", ["enable-automation"]) 43 | options.add_experimental_option("useAutomationExtension", False) 44 | prefs = {"profile.managed_default_content_settings.images": 2} 45 | options.add_experimental_option("prefs", prefs) 46 | options.add_argument("user-data-dir=.profile-bb") 47 | 48 | 49 | class BestBuyHandler: 50 | def __init__(self, sku_id, headless=False): 51 | self.notification_handler = NotificationHandler() 52 | self.sku_id = sku_id 53 | self.session = requests.Session() 54 | self.auto_buy = False 55 | self.account = {"username": "", "password": ""} 56 | 57 | adapter = HTTPAdapter( 58 | max_retries=Retry( 59 | total=3, 60 | backoff_factor=1, 61 | status_forcelist=[429, 500, 502, 503, 504], 62 | method_whitelist=["HEAD", "GET", "OPTIONS", "POST"], 63 | ) 64 | ) 65 | self.session.mount("https://", adapter) 66 | self.session.mount("http://", adapter) 67 | 68 | response = self.session.get( 69 | BEST_BUY_PDP_URL.format(sku=self.sku_id), headers=DEFAULT_HEADERS 70 | ) 71 | log.info(f"PDP Request: {response.status_code}") 72 | self.product_url = response.url 73 | log.info(f"Product URL: {self.product_url}") 74 | 75 | self.session.get(self.product_url) 76 | log.info(f"Product URL Request: {response.status_code}") 77 | 78 | if self.auto_buy: 79 | log.info("Loading headless driver.") 80 | if headless: 81 | enable_headless() # TODO - check if this still messes up the cookies. 82 | options.add_argument( 83 | "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36" 84 | ) 85 | 86 | self.driver = webdriver.Chrome( 87 | executable_path=binary_path, 88 | options=options, 89 | ) 90 | log.info("Loading https://www.bestbuy.com.") 91 | self.login() 92 | 93 | self.driver.get(self.product_url) 94 | cookies = self.driver.get_cookies() 95 | 96 | [ 97 | self.session.cookies.set_cookie( 98 | requests.cookies.create_cookie( 99 | domain=cookie["domain"], 100 | name=cookie["name"], 101 | value=cookie["value"], 102 | ) 103 | ) 104 | for cookie in cookies 105 | ] 106 | 107 | # self.driver.quit() 108 | 109 | log.info("Calling location/v1/US/approximate") 110 | log.info( 111 | self.session.get( 112 | "https://www.bestbuy.com/location/v1/US/approximate", 113 | headers=DEFAULT_HEADERS, 114 | ).status_code 115 | ) 116 | 117 | log.info("Calling basket/v1/basketCount") 118 | log.info( 119 | self.session.get( 120 | "https://www.bestbuy.com/basket/v1/basketCount", 121 | headers={ 122 | "x-client-id": "browse", 123 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36", 124 | "Accept": "application/json", 125 | }, 126 | ).status_code 127 | ) 128 | 129 | def login(self): 130 | self.driver.get("https://www.bestbuy.com/identity/global/signin") 131 | self.driver.find_element_by_xpath('//*[@id="fld-e"]').send_keys( 132 | self.account["username"] 133 | ) 134 | self.driver.find_element_by_xpath('//*[@id="fld-p1"]').send_keys( 135 | self.account["password"] 136 | ) 137 | self.driver.find_element_by_xpath( 138 | "/html/body/div[1]/div/section/main/div[1]/div/div/div/div/form/div[3]/div/label/div/i" 139 | ).click() 140 | self.driver.find_element_by_xpath( 141 | "/html/body/div[1]/div/section/main/div[1]/div/div/div/div/form/div[4]/button" 142 | ).click() 143 | WebDriverWait(self.driver, 10).until( 144 | lambda x: "Official Online Store" in self.driver.title 145 | ) 146 | 147 | def run_item(self): 148 | while not self.in_stock(): 149 | sleep(5) 150 | log.info(f"Item {self.sku_id} is in stock!") 151 | if self.auto_buy: 152 | self.auto_checkout() 153 | else: 154 | cart_url = self.add_to_cart() 155 | self.notification_handler.send_notification( 156 | f"SKU: {self.sku_id} in stock: {cart_url}" 157 | ) 158 | 159 | def in_stock(self): 160 | log.info("Checking stock") 161 | url = "https://www.bestbuy.com/api/tcfb/model.json?paths=%5B%5B%22shop%22%2C%22scds%22%2C%22v2%22%2C%22page%22%2C%22tenants%22%2C%22bbypres%22%2C%22pages%22%2C%22globalnavigationv5sv%22%2C%22header%22%5D%2C%5B%22shop%22%2C%22buttonstate%22%2C%22v5%22%2C%22item%22%2C%22skus%22%2C{}%2C%22conditions%22%2C%22NONE%22%2C%22destinationZipCode%22%2C%22%2520%22%2C%22storeId%22%2C%22%2520%22%2C%22context%22%2C%22cyp%22%2C%22addAll%22%2C%22false%22%5D%5D&method=get".format( 162 | self.sku_id 163 | ) 164 | response = self.session.get(url, headers=DEFAULT_HEADERS) 165 | log.info(f"Stock check response code: {response.status_code}") 166 | try: 167 | response_json = response.json() 168 | item_json = find_values( 169 | json.dumps(response_json), "buttonStateResponseInfos" 170 | ) 171 | item_state = item_json[0][0]["buttonState"] 172 | log.info(f"Item state is: {item_state}") 173 | if item_json[0][0]["skuId"] == self.sku_id and item_state in [ 174 | "ADD_TO_CART", 175 | "PRE_ORDER", 176 | ]: 177 | return True 178 | else: 179 | return False 180 | except Exception as e: 181 | log.warning("Error parsing json. Using string search to determine state.") 182 | log.info(response_json) 183 | log.error(e) 184 | if "ADD_TO_CART" in response.text: 185 | log.info("Item is in stock!") 186 | return True 187 | else: 188 | log.info("Item is out of stock") 189 | return False 190 | 191 | def add_to_cart(self): 192 | webbrowser.open_new(BEST_BUY_CART_URL.format(sku=self.sku_id)) 193 | return BEST_BUY_CART_URL.format(sku=self.sku_id) 194 | 195 | def auto_checkout(self): 196 | self.auto_add_to_cart() 197 | self.start_checkout() 198 | self.driver.get("https://www.bestbuy.com/checkout/c/r/fast-track") 199 | 200 | def auto_add_to_cart(self): 201 | log.info("Attempting to auto add to cart...") 202 | 203 | body = {"items": [{"skuId": self.sku_id}]} 204 | headers = { 205 | "Accept": "application/json", 206 | "authority": "www.bestbuy.com", 207 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36", 208 | "Content-Type": "application/json; charset=UTF-8", 209 | "Sec-Fetch-Site": "same-origin", 210 | "Sec-Fetch-Mode": "cors", 211 | "Sec-Fetch-Dest": "empty", 212 | "origin": "https://www.bestbuy.com", 213 | "referer": self.product_url, 214 | "Content-Length": str(len(json.dumps(body))), 215 | } 216 | # [ 217 | # log.info({'name': c.name, 'value': c.value, 'domain': c.domain, 'path': c.path}) 218 | # for c in self.session.cookies 219 | # ] 220 | log.info("Making request") 221 | response = self.session.post( 222 | BEST_BUY_ADD_TO_CART_API_URL, json=body, headers=headers, timeout=5 223 | ) 224 | log.info(response.status_code) 225 | if ( 226 | response.status_code == 200 227 | and response.json()["cartCount"] > 0 228 | and self.sku_id in response.text 229 | ): 230 | log.info(f"Added {self.sku_id} to cart!") 231 | log.info(response.json()) 232 | else: 233 | log.info(response.status_code) 234 | log.info(response.json()) 235 | 236 | def start_checkout(self): 237 | headers = { 238 | "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", 239 | "accept-encoding": "gzip, deflate, br", 240 | "accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7", 241 | "upgrade-insecure-requests": "1", 242 | "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36", 243 | } 244 | while True: 245 | log.info("Starting Checkout") 246 | response = self.session.post( 247 | "https://www.bestbuy.com/cart/d/checkout", headers=headers, timeout=5 248 | ) 249 | if response.status_code == 200: 250 | response_json = response.json() 251 | log.info(response_json) 252 | self.order_id = response_json["updateData"]["order"]["id"] 253 | self.item_id = response_json["updateData"]["order"]["lineItems"][0][ 254 | "id" 255 | ] 256 | log.info(f"Started Checkout for order id: {self.order_id}") 257 | log.info(response_json) 258 | if response_json["updateData"]["redirectUrl"]: 259 | self.session.get( 260 | response_json["updateData"]["redirectUrl"], headers=headers 261 | ) 262 | return 263 | log.info("Error Starting Checkout") 264 | sleep(5) 265 | 266 | def submit_shipping(self): 267 | log.info("Starting Checkout") 268 | headers = { 269 | "accept": "application/json, text/javascript, */*; q=0.01", 270 | "accept-encoding": "gzip, deflate, br", 271 | "accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7", 272 | "content-type": "application/json", 273 | "origin": "https://www.bestbuy.com", 274 | "referer": "https://www.bestbuy.com/cart", 275 | "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36", 276 | "x-user-interface": "DotCom-Optimized", 277 | "x-order-id": self.order_id, 278 | } 279 | while True: 280 | log.info("Submitting Shipping") 281 | body = {"selected": "SHIPPING"} 282 | response = self.session.put( 283 | "https://www.bestbuy.com/cart/item/{item_id}/fulfillment".format( 284 | item_id=self.item_id 285 | ), 286 | headers=headers, 287 | json=body, 288 | ) 289 | response_json = response.json() 290 | log.info(response.status_code) 291 | log.info(response_json) 292 | if ( 293 | response.status_code == 200 294 | and response_json["order"]["id"] == self.order_id 295 | ): 296 | log.info("Submitted Shipping") 297 | return True 298 | else: 299 | log.info("Error Submitting Shipping") 300 | 301 | def submit_payment(self, tas_data): 302 | body = { 303 | "items": [ 304 | { 305 | "id": self.item_id, 306 | "type": "DEFAULT", 307 | "selectedFulfillment": {"shipping": {"address": {}}}, 308 | "giftMessageSelected": False, 309 | } 310 | ] 311 | } 312 | headers = { 313 | "accept": "application/com.bestbuy.order+json", 314 | "accept-encoding": "gzip, deflate, br", 315 | "accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7", 316 | "content-type": "application/json", 317 | "origin": "https://www.bestbuy.com", 318 | "referer": "https://www.bestbuy.com/checkout/r/fulfillment", 319 | "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36", 320 | "x-user-interface": "DotCom-Optimized", 321 | } 322 | r = self.session.patch( 323 | "https://www.bestbuy.com/checkout/d/orders/{}/".format(self.order_id), 324 | json=body, 325 | headers=headers, 326 | ) 327 | [ 328 | log.info( 329 | {"name": c.name, "value": c.value, "domain": c.domain, "path": c.path} 330 | ) 331 | for c in self.session.cookies 332 | ] 333 | log.info(r.status_code) 334 | log.info(r.text) 335 | 336 | def get_tas_data(self): 337 | headers = { 338 | "accept": "*/*", 339 | "accept-encoding": "gzip, deflate, br", 340 | "accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7", 341 | "content-type": "application/json", 342 | "referer": "https://www.bestbuy.com/checkout/r/payment", 343 | "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36", 344 | } 345 | while True: 346 | try: 347 | log.info("Getting TAS Data") 348 | r = requests.get( 349 | "https://www.bestbuy.com/api/csiservice/v2/key/tas", headers=headers 350 | ) 351 | log.info("Got TAS Data") 352 | return json.loads(r.text) 353 | except Exception as e: 354 | sleep(5) 355 | -------------------------------------------------------------------------------- /stores/evga.py: -------------------------------------------------------------------------------- 1 | import json 2 | import pickle 3 | from os import path 4 | from time import sleep 5 | 6 | from chromedriver_py import binary_path # this will get you the path variable 7 | from selenium import webdriver 8 | from selenium.webdriver.common.by import By 9 | from selenium.webdriver.support import expected_conditions as EC 10 | from selenium.webdriver.support.ui import Select 11 | from selenium.webdriver.support.ui import WebDriverWait 12 | 13 | from utils import selenium_utils 14 | from utils.logger import log 15 | from utils.selenium_utils import options, enable_headless 16 | 17 | LOGIN_URL = "https://secure.evga.com/us/login.asp" 18 | CONFIG_PATH = "evga_config.json" 19 | 20 | 21 | class Evga: 22 | def __init__(self, headless=False): 23 | if headless: 24 | enable_headless() 25 | self.driver = webdriver.Chrome(executable_path=binary_path, options=options) 26 | self.credit_card = {} 27 | self.card_pn = "" 28 | self.card_series = "" 29 | try: 30 | if path.exists(CONFIG_PATH): 31 | with open(CONFIG_PATH) as json_file: 32 | config = json.load(json_file) 33 | username = config["username"] 34 | password = config["password"] 35 | self.card_pn = config.get("card_pn") 36 | self.card_series = config["card_series"] 37 | self.credit_card["name"] = config["credit_card"]["name"] 38 | self.credit_card["number"] = config["credit_card"]["number"] 39 | self.credit_card["cvv"] = config["credit_card"]["cvv"] 40 | self.credit_card["expiration_month"] = config["credit_card"][ 41 | "expiration_month" 42 | ] 43 | self.credit_card["expiration_year"] = config["credit_card"][ 44 | "expiration_year" 45 | ] 46 | except Exception as e: 47 | log.error(f"This is most likely an error with your {CONFIG_PATH} file.") 48 | raise e 49 | 50 | self.login(username, password) 51 | 52 | def login(self, username, password): 53 | """ 54 | We're just going to attempt to load cookies, else enter the user info and let the user handle the captcha 55 | :param username: 56 | :param password: 57 | :return: 58 | """ 59 | self.driver.execute_cdp_cmd( 60 | "Network.setUserAgentOverride", 61 | { 62 | "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.53 Safari/537.36" 63 | }, 64 | ) 65 | self.driver.execute_script( 66 | "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})" 67 | ) 68 | 69 | if path.isfile("evga-cookies.pkl"): # check for cookies file 70 | self.driver.get("https://www.evga.com") 71 | selenium_utils.wait_for_page( 72 | self.driver, "EVGA - Intelligent Innovation - Official Website", 300 73 | ) 74 | cookies = pickle.load(open("evga-cookies.pkl", "rb")) 75 | for cookie in cookies: 76 | self.driver.add_cookie(cookie) 77 | 78 | self.driver.get("https://www.evga.com") 79 | selenium_utils.wait_for_page( 80 | self.driver, "EVGA - Intelligent Innovation - Official Website", 300 81 | ) 82 | if ( 83 | len(self.driver.find_elements_by_id("svg-login")) > 0 84 | ): # cookies did not provide logged in state 85 | self.driver.get(LOGIN_URL) 86 | selenium_utils.wait_for_page(self.driver, "EVGA - Intelligent Innovation") 87 | 88 | selenium_utils.field_send_keys(self.driver, "evga_login", username) 89 | selenium_utils.field_send_keys(self.driver, "password", password) 90 | 91 | log.info("Go do the captcha and log in") 92 | 93 | selenium_utils.wait_for_page( 94 | self.driver, "EVGA - Intelligent Innovation - Official Website", 300 95 | ) 96 | pickle.dump( 97 | self.driver.get_cookies(), open("evga-cookies.pkl", "wb") 98 | ) # save cookies 99 | 100 | log.info("Logged in!") 101 | 102 | def buy(self, delay=5, test=False): 103 | if test: 104 | log.info("Refreshing Page Until Title Matches ...") 105 | selenium_utils.wait_for_title( 106 | self.driver, 107 | "EVGA - Products - Graphics - GeForce 16 Series Family - GTX 1660", 108 | "https://www.evga.com/products/ProductList.aspx?type=0&family=GeForce+16+Series+Family&chipset=GTX+1660", 109 | ) 110 | else: 111 | log.info("Refreshing Page Until Title Matches ...") 112 | selenium_utils.wait_for_title( 113 | self.driver, 114 | "EVGA - Products - Graphics - GeForce 30 Series Family - RTX " 115 | + self.card_series, 116 | "https://www.evga.com/products/productlist.aspx?type=0&family=GeForce+30+Series+Family&chipset=RTX+" 117 | + self.card_series, 118 | ) 119 | 120 | log.info("matched chipset=RTX+" + self.card_series + "!") 121 | 122 | if self.card_pn and not test: 123 | # check for card 124 | log.info("On GPU list Page") 125 | card_btn = self.driver.find_elements_by_xpath( 126 | "//a[@href='/products/product.aspx?pn=" + self.card_pn + "']" 127 | ) 128 | while not card_btn: 129 | log.debug("Refreshing page for GPU") 130 | self.driver.refresh() 131 | card_btn = self.driver.find_elements_by_xpath( 132 | "//a[@href='/products/product.aspx?pn=" + self.card_pn + "']" 133 | ) 134 | sleep(delay) 135 | 136 | card_btn[0].click() 137 | 138 | # Check for stock 139 | log.info("On GPU Page") 140 | atc_buttons = self.driver.find_elements_by_xpath( 141 | '//input[@class="btnBigAddCart"]' 142 | ) 143 | while not atc_buttons: 144 | log.debug("Refreshing page for GPU") 145 | self.driver.refresh() 146 | atc_buttons = self.driver.find_elements_by_xpath( 147 | '//input[@class="btnBigAddCart"]' 148 | ) 149 | sleep(delay) 150 | 151 | # Add to cart 152 | atc_buttons[0].click() 153 | 154 | # Go to checkout 155 | selenium_utils.wait_for_page(self.driver, "EVGA - Checkout") 156 | selenium_utils.button_click_using_xpath( 157 | self.driver, '//*[@id="LFrame_CheckoutButton"]' 158 | ) 159 | 160 | # Shipping Address screen 161 | selenium_utils.wait_for_page(self.driver, "Shopping") 162 | 163 | log.info("Skip that page.") 164 | self.driver.get("https://secure.evga.com/Cart/Checkout_Payment.aspx") 165 | 166 | selenium_utils.wait_for_page(self.driver, "EVGA - Checkout - Billing Options") 167 | 168 | log.info("Ensure that we are paying with credit card") 169 | sleep(1) # Fix this. 170 | WebDriverWait(self.driver, 10).until( 171 | EC.element_to_be_clickable((By.XPATH, './/input[@value="rdoCreditCard"]')) 172 | ).click() 173 | WebDriverWait(self.driver, 10).until( 174 | EC.element_to_be_clickable( 175 | (By.XPATH, '//*[@id="ctl00_LFrame_btncontinue"]') 176 | ) 177 | ).click() 178 | 179 | selenium_utils.wait_for_element(self.driver, "ctl00_LFrame_txtNameOnCard") 180 | 181 | log.info("Populate credit card fields") 182 | 183 | selenium_utils.field_send_keys( 184 | self.driver, "ctl00$LFrame$txtNameOnCard", self.credit_card["name"] 185 | ) 186 | selenium_utils.field_send_keys( 187 | self.driver, "ctl00$LFrame$txtCardNumber", self.credit_card["number"] 188 | ) 189 | selenium_utils.field_send_keys( 190 | self.driver, "ctl00$LFrame$txtCvv", self.credit_card["cvv"] 191 | ) 192 | Select(self.driver.find_element_by_id("ctl00_LFrame_ddlMonth")).select_by_value( 193 | self.credit_card["expiration_month"] 194 | ) 195 | Select(self.driver.find_element_by_id("ctl00_LFrame_ddlYear")).select_by_value( 196 | self.credit_card["expiration_year"] 197 | ) 198 | WebDriverWait(self.driver, 10).until( 199 | EC.element_to_be_clickable( 200 | ( 201 | By.XPATH, 202 | "/html/body/form/div[3]/div[3]/div/div[1]/div[5]/div[3]/div/div[1]/div/div[@id='checkoutButtons']/input[2]", 203 | ) 204 | ) 205 | ).click() 206 | 207 | try: 208 | WebDriverWait(self.driver, 10).until( 209 | EC.element_to_be_clickable( 210 | ( 211 | By.XPATH, 212 | "/html/body/form/div[3]/div[3]/div/div[1]/div[5]/div[3]/div/div[1]/div/div[@id='checkoutButtons']/input[2]", 213 | ) 214 | ) 215 | ).click() 216 | except: 217 | pass 218 | 219 | log.info("Finalize Order Page") 220 | selenium_utils.wait_for_page(self.driver, "EVGA - Checkout - Finalize Order") 221 | 222 | WebDriverWait(self.driver, 10).until( 223 | EC.element_to_be_clickable((By.ID, "ctl00_LFrame_cbAgree")) 224 | ).click() 225 | 226 | if not test: 227 | WebDriverWait(self.driver, 10).until( 228 | EC.element_to_be_clickable((By.ID, "ctl00_LFrame_btncontinue")) 229 | ).click() 230 | 231 | log.info("Finalized Order!") 232 | -------------------------------------------------------------------------------- /stores/nvidia.py: -------------------------------------------------------------------------------- 1 | import concurrent 2 | import json 3 | import webbrowser 4 | from concurrent.futures.thread import ThreadPoolExecutor 5 | from datetime import datetime 6 | from time import sleep 7 | 8 | import requests 9 | from requests.exceptions import Timeout 10 | from requests.packages.urllib3.util.retry import Retry 11 | from spinlog import Spinner 12 | 13 | from notifications.notifications import NotificationHandler 14 | from utils.http import TimeoutHTTPAdapter 15 | from utils.logger import log 16 | 17 | NVIDIA_PRODUCT_API = "https://api.nvidia.partners/edge/product/search?page=1&limit=9&locale=en-us&category=GPU" 18 | NVIDIA_CART_URL = "https://store.nvidia.com/store?Action=AddItemToRequisition&SiteID=nvidia&Locale=en_US&productID={product_id}&quantity=1" 19 | NVIDIA_TOKEN_URL = "https://store.nvidia.com/store/nvidia/SessionToken" 20 | NVIDIA_STOCK_API = "https://api-prod.nvidia.com/direct-sales-shop/DR/products/{locale}/USD/{product_id}" 21 | NVIDIA_ADD_TO_CART_API = "https://api-prod.nvidia.com/direct-sales-shop/DR/add-to-cart" 22 | 23 | GPU_DISPLAY_NAMES = { 24 | "2060S": "NVIDIA GEFORCE RTX 2060 SUPER", 25 | "3080": "NVIDIA GEFORCE RTX 3080", 26 | "3090": "NVIDIA GEFORCE RTX 3090", 27 | } 28 | 29 | ACCEPTED_LOCALES = [ 30 | "en_us", 31 | "en_gb", 32 | "de_de", 33 | "fr_fr", 34 | "it_it", 35 | "es_es", 36 | "nl_nl", 37 | "sv_se", 38 | "de_at", 39 | "fr_be", 40 | "da_dk", 41 | "cs_cz", 42 | ] 43 | 44 | PAGE_TITLES_BY_LOCALE = { 45 | "en_us": { # Verified 46 | "signed_in_help": "NVIDIA Online Store - Help", 47 | "checkout": "NVIDIA Online Store - Checkout", 48 | "verify_order": "NVIDIA Online Store - Verify Order", 49 | "address_validation": "NVIDIA Online Store - Address Validation Suggestion Page", 50 | "order_completed": "NVIDIA Online Store - Order Completed", 51 | }, 52 | "fr_be": { 53 | "signed_in_help": "NVIDIA Online Store - Help", 54 | "checkout": "NVIDIA Online Store - Checkout", 55 | "verify_order": "NVIDIA Online Store - Verify Order", 56 | "address_validation": "NVIDIA Online Store - Address Validation Suggestion Page", 57 | "order_completed": "NVIDIA Online Store - Order Completed", 58 | }, 59 | "es_es": { 60 | "signed_in_help": "NVIDIA Tienda electrónica - Ayuda", 61 | "checkout": "NVIDIA Tienda electrónica - Caja", 62 | "verify_order": "NVIDIA Tienda electrónica - Verificar pedido", 63 | "address_validation": "NVIDIA Tienda electrónica - Página de sugerencia para la validación de la dirección", 64 | "order_completed": "NVIDIA Online Store - Order Completed", 65 | }, 66 | "fr_fr": { 67 | "signed_in_help": "NVIDIA Boutique en ligne - Aide", 68 | "checkout": "NVIDIA Boutique en ligne - panier et informations de facturation", 69 | "verify_order": "NVIDIA Boutique en ligne - vérification de commande", 70 | "address_validation": "NVIDIA Boutique en ligne - Page de suggestion et de validation d’adresse", 71 | "order_completed": "NVIDIA Boutique en ligne - confirmation de commande", 72 | }, 73 | "it_it": { 74 | "signed_in_help": "NVIDIA Negozio Online - Guida", 75 | "checkout": "NVIDIA Negozio Online - Vai alla cassa", 76 | "verify_order": "NVIDIA Negozio Online - Verifica ordine", 77 | "address_validation": "NVIDIA Negozio Online - Pagina di suggerimento per la validazione dell'indirizzo", 78 | "order_completed": "NVIDIA Negozio Online - Ordine completato", 79 | }, 80 | "nl_nl": { 81 | "signed_in_help": "NVIDIA Online winkel - Help", 82 | "checkout": "NVIDIA Online winkel - Kassa", 83 | "verify_order": "NVIDIA Online winkel - Bestelling controleren", 84 | "address_validation": "NVIDIA Online winkel - Adres Validatie Suggestie pagina", 85 | "order_completed": "NVIDIA Online winkel - Bestelling voltooid", 86 | }, 87 | "sv_se": { 88 | "signed_in_help": "NVIDIA Online Store - Help", 89 | "checkout": "NVIDIA Online Store - Checkout", 90 | "verify_order": "NVIDIA Online Store - Verify Order", 91 | "address_validation": "NVIDIA Online Store - Address Validation Suggestion Page", 92 | "order_completed": "NVIDIA Online Store - Order Completed", 93 | }, 94 | "de_de": { 95 | "signed_in_help": "NVIDIA Online-Shop - Hilfe", 96 | "checkout": "NVIDIA Online-Shop - einkaufswagen", 97 | "verify_order": "NVIDIA Online-Shop - bestellung überprüfen und bestätigen", 98 | "address_validation": "NVIDIA Online-Shop - Adressüberprüfung Vorschlagsseite", 99 | "order_completed": "NVIDIA Online Store - Order Completed", 100 | }, 101 | "de_at": { 102 | "signed_in_help": "NVIDIA Online-Shop - Hilfe", 103 | "checkout": "NVIDIA Online-Shop - einkaufswagen", 104 | "verify_order": "NVIDIA Online-Shop - bestellung überprüfen und bestätigen", 105 | "address_validation": "NVIDIA Online-Shop - Adressüberprüfung Vorschlagsseite", 106 | "order_completed": "NVIDIA Online Store - Order Completed", 107 | }, 108 | "en_gb": { 109 | "signed_in_help": "NVIDIA Online Store - Help", 110 | "checkout": "NVIDIA Online Store - Checkout", 111 | "verify_order": "NVIDIA Online Store - Verify Order", 112 | "address_validation": "NVIDIA Online Store - Address Validation Suggestion Page", 113 | "order_completed": "NVIDIA Online Store - Order Completed", 114 | }, 115 | "da_dk": { 116 | "signed_in_help": "NVIDIA Online Store - Help", 117 | "checkout": "NVIDIA Online Store - Checkout", 118 | "verify_order": "NVIDIA Online Store - Verify Order", 119 | "address_validation": "NVIDIA Online Store - Address Validation Suggestion Page", 120 | "order_completed": "NVIDIA Online Store - Order Completed", 121 | }, 122 | "cs_cz": { 123 | "signed_in_help": "NVIDIA Online Store - Help", 124 | "checkout": "NVIDIA Online Store - Checkout", 125 | "verify_order": "NVIDIA Online Store - Verify Order", 126 | "address_validation": "NVIDIA Online Store - Address Validation Suggestion Page", 127 | "order_completed": "NVIDIA Online Store - Order Completed", 128 | }, 129 | } 130 | 131 | autobuy_locale_btns = { 132 | "fr_be": ["continuer", "envoyer"], 133 | "es_es": ["continuar", "enviar"], 134 | "fr_fr": ["continuer", "envoyer"], 135 | "it_it": ["continua", "invia"], 136 | "nl_nl": ["doorgaan", "indienen"], 137 | "sv_se": ["continue", "submit"], 138 | "de_de": ["Weiter", "Senden"], 139 | "de_at": ["Weiter", "Senden"], 140 | "en_gb": ["Continue Checkout", "submit"], 141 | "en_us": ["continue", "submit"], 142 | "da_dk": ["continue", "submit"], 143 | "cs_cz": ["continue", "submit"], 144 | } 145 | 146 | DEFAULT_HEADERS = { 147 | "Accept": "application/json", 148 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36", 149 | } 150 | CART_SUCCESS_CODES = {201, requests.codes.ok} 151 | 152 | AUTOBUY_CONFIG_PATH = "autobuy_config.json" 153 | AUTOBUY_CONFIG_KEYS = ["NVIDIA_LOGIN", "NVIDIA_PASSWORD"] 154 | 155 | 156 | class ProductIDChangedException(Exception): 157 | def __init__(self): 158 | super().__init__("Product IDS changed. We need to re run.") 159 | 160 | 161 | class InvalidAutoBuyConfigException(Exception): 162 | def __init__(self, provided_json): 163 | super().__init__( 164 | f"Check the README and update your `autobuy_config.json` file. Your autobuy config is {json.dumps(provided_json, indent=2)}" 165 | ) 166 | 167 | 168 | PRODUCT_IDS_FILE = "stores/store_data/nvidia_product_ids.json" 169 | PRODUCT_IDS = json.load(open(PRODUCT_IDS_FILE)) 170 | 171 | 172 | class NvidiaBuyer: 173 | def __init__(self, gpu, locale="en_us", test=False, interval=5): 174 | self.product_ids = set([]) 175 | self.cli_locale = locale.lower() 176 | self.locale = self.map_locales() 177 | self.session = requests.Session() 178 | self.gpu = gpu 179 | self.enabled = True 180 | self.auto_buy_enabled = False 181 | self.attempt = 0 182 | self.started_at = datetime.now() 183 | self.test = test 184 | self.interval = interval 185 | 186 | self.gpu_long_name = GPU_DISPLAY_NAMES[gpu] 187 | 188 | # Disable auto_buy_enabled if the user does not provide a bool. 189 | if type(self.auto_buy_enabled) != bool: 190 | self.auto_buy_enabled = False 191 | 192 | adapter = TimeoutHTTPAdapter( 193 | max_retries=Retry( 194 | total=10, 195 | backoff_factor=1, 196 | status_forcelist=[429, 500, 502, 503, 504], 197 | method_whitelist=["HEAD", "GET", "OPTIONS"], 198 | ) 199 | ) 200 | self.session.mount("https://", adapter) 201 | self.session.mount("http://", adapter) 202 | self.notification_handler = NotificationHandler() 203 | 204 | self.get_product_ids() 205 | 206 | def map_locales(self): 207 | if self.cli_locale == "de_at": 208 | return "de_de" 209 | if self.cli_locale == "fr_be": 210 | return "fr_fr" 211 | if self.cli_locale == "da_dk": 212 | return "en_gb" 213 | if self.cli_locale == "cs_cz": 214 | return "en_gb" 215 | return self.cli_locale 216 | 217 | def get_product_ids(self): 218 | if isinstance(PRODUCT_IDS[self.locale][self.gpu], list): 219 | self.product_ids = PRODUCT_IDS[self.locale][self.gpu] 220 | if isinstance(PRODUCT_IDS[self.locale][self.gpu], str): 221 | self.product_ids = [PRODUCT_IDS[self.locale][self.gpu]] 222 | 223 | def run_items(self): 224 | log.info( 225 | f"We have {len(self.product_ids)} product IDs for {self.gpu_long_name}" 226 | ) 227 | log.info(f"Product IDs: {self.product_ids}") 228 | try: 229 | with ThreadPoolExecutor(max_workers=len(self.product_ids)) as executor: 230 | product_futures = [ 231 | executor.submit(self.buy, product_id) 232 | for product_id in self.product_ids 233 | ] 234 | concurrent.futures.wait(product_futures) 235 | for fut in product_futures: 236 | log.debug(f"Future Result: {fut.result()}") 237 | except ProductIDChangedException as ex: 238 | log.warning("Product IDs changed.") 239 | self.product_ids = set([]) 240 | self.get_product_ids() 241 | self.run_items() 242 | 243 | def buy(self, product_id): 244 | pass 245 | try: 246 | log.info( 247 | f"Stock Check {product_id} at {self.interval} second intervals." 248 | ) 249 | while not self.is_in_stock(product_id): 250 | self.attempt = self.attempt + 1 251 | time_delta = str(datetime.now() - self.started_at).split(".")[0] 252 | with Spinner.get( 253 | f"Stock Check ({self.attempt}, have been running for {time_delta})..." 254 | ) as s: 255 | sleep(self.interval) 256 | if self.enabled: 257 | cart_success, cart_url = self.get_cart_url(product_id) 258 | if cart_success: 259 | log.info(f"{self.gpu_long_name} added to cart.") 260 | self.enabled = False 261 | webbrowser.open(cart_url) 262 | self.notification_handler.send_notification( 263 | f" {self.gpu_long_name} with product ID: {product_id} in " 264 | f"stock: {cart_url}" 265 | ) 266 | else: 267 | self.buy(product_id) 268 | except Timeout: 269 | log.error("Had a timeout error.") 270 | self.buy(product_id) 271 | 272 | def is_in_stock(self, product_id): 273 | response = self.session.get( 274 | NVIDIA_STOCK_API.format(product_id=product_id, locale=self.locale), 275 | headers=DEFAULT_HEADERS, 276 | ) 277 | log.debug(f"Stock check response code: {response.status_code}") 278 | if response.status_code != 200: 279 | log.debug(response.text) 280 | if "PRODUCT_INVENTORY_IN_STOCK" in response.text: 281 | return True 282 | else: 283 | return False 284 | 285 | def get_cart_url(self, product_id): 286 | success, token = self.get_session_token() 287 | if not success: 288 | return False, "" 289 | 290 | data = {"products": [{"productId": product_id, "quantity": 1}]} 291 | headers = DEFAULT_HEADERS.copy() 292 | headers["locale"] = self.locale 293 | headers["nvidia_shop_id"] = token 294 | headers["Content-Type"] = "application/json" 295 | response = self.session.post( 296 | url=NVIDIA_ADD_TO_CART_API, headers=headers, data=json.dumps(data) 297 | ) 298 | if response.status_code == 203: 299 | response_json = response.json() 300 | if "location" in response_json: 301 | return True, response_json["location"] 302 | else: 303 | log.error(response.text) 304 | log.error(f"Add to cart failed with {response.status_code}. This is likely an error with nvidia's API.") 305 | return False, "" 306 | 307 | def get_session_token(self): 308 | params = {"format": "json", "locale": self.locale} 309 | headers = DEFAULT_HEADERS.copy() 310 | headers["locale"] = self.locale 311 | 312 | response = self.session.get( 313 | NVIDIA_TOKEN_URL, headers=DEFAULT_HEADERS, params=params 314 | ) 315 | if response.status_code == 200: 316 | response_json = response.json() 317 | if "session_token" not in response_json: 318 | log.error("Error getting session token.") 319 | return False, "" 320 | return True, response_json["session_token"] 321 | else: 322 | log.debug(f"Get Session Token: {response.status_code}") -------------------------------------------------------------------------------- /stores/store_data/nvidia_product_ids.json: -------------------------------------------------------------------------------- 1 | { 2 | "fr_be": { 3 | "2060S": "5394902700", 4 | "3070": "", 5 | "3080": "5438795700", 6 | "3090": "" 7 | }, 8 | "es_es": { 9 | "2060S": "", 10 | "3070": "", 11 | "3080": "5438794800", 12 | "3090": "" 13 | }, 14 | "fr_fr": { 15 | "2060S": "5394902700", 16 | "3070": "", 17 | "3080": "5438795200", 18 | "3090": "" 19 | }, 20 | "it_it": { 21 | "2060S": "", 22 | "3070": "", 23 | "3080": "5438796200", 24 | "3090": "" 25 | }, 26 | "nl_nl": { 27 | "2060S": "5394903500", 28 | "3070": "", 29 | "3080": "5438796700", 30 | "3090": "" 31 | }, 32 | "sv_se": { 33 | "2060S": "", 34 | "3070": "", 35 | "3080": "5438798100", 36 | "3090": "" 37 | }, 38 | "de_de": { 39 | "2060S": "5394902900", 40 | "3070": "", 41 | "3080": "5438792300", 42 | "3090": "5438761400" 43 | }, 44 | "de_at": { 45 | "2060S": "5394902900", 46 | "3070": "", 47 | "3080": "5440853700", 48 | "3090": "5438761400" 49 | }, 50 | "en_gb": { 51 | "2060S": "5394903300", 52 | "3070": "", 53 | "3080": "5438792800", 54 | "3090": "5438792700" 55 | }, 56 | "en_us": { 57 | "2060S": "5379432500", 58 | "3070": "", 59 | "3080": "5438481700", 60 | "3090": "5438481600" 61 | }, 62 | "da_dk": { 63 | "2060S": "", 64 | "3070": "", 65 | "3080": "", 66 | "3090": "" 67 | }, 68 | "cs_cz": { 69 | "2060S": "", 70 | "3070": "", 71 | "3080": "", 72 | "3090": "" 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /telegram_config.template_json: -------------------------------------------------------------------------------- 1 | { 2 | "BOT_TOKEN" : "1234567890:abcdefghijklmnopqrstuvwxyz", 3 | "BOT_CHAT_ID" : "111222333" 4 | } 5 | -------------------------------------------------------------------------------- /twilio_config.template_json: -------------------------------------------------------------------------------- 1 | { 2 | "account_sid": "ACCOUNT_SID", 3 | "auth_token": "AUTH_TOKEN", 4 | "from": "YOUR TWILIO NUMBER", 5 | "to": "THE NUMBER YOU WANT TO SEND SMS TO" 6 | } -------------------------------------------------------------------------------- /utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evanotero/nvidia-bot/478c047345bb1bed317a5c266d3905132f96cf9f/utils/__init__.py -------------------------------------------------------------------------------- /utils/http.py: -------------------------------------------------------------------------------- 1 | from requests.adapters import HTTPAdapter 2 | from requests.packages.urllib3.util.retry import Retry 3 | 4 | DEFAULT_TIMEOUT = 5 # seconds 5 | 6 | 7 | class TimeoutHTTPAdapter(HTTPAdapter): 8 | def __init__(self, *args, **kwargs): 9 | self.timeout = DEFAULT_TIMEOUT 10 | super().__init__( 11 | max_retries=Retry( 12 | total=10, 13 | backoff_factor=1, 14 | status_forcelist=[429, 500, 502, 503, 504], 15 | method_whitelist=["HEAD", "GET", "OPTIONS"], 16 | ) 17 | ) 18 | 19 | def send(self, request, **kwargs): 20 | timeout = kwargs.get("timeout") 21 | if timeout is None: 22 | kwargs["timeout"] = self.timeout 23 | return super().send(request, **kwargs) 24 | -------------------------------------------------------------------------------- /utils/json_utils.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | 4 | def find_values(json_repr, id): 5 | results = [] 6 | 7 | def _decode_dict(a_dict): 8 | try: 9 | results.append(a_dict[id]) 10 | except KeyError: 11 | pass 12 | return a_dict 13 | 14 | json.loads(json_repr, object_hook=_decode_dict) # Return value ignored. 15 | return results 16 | 17 | 18 | class InvalidAutoBuyConfigException(Exception): 19 | def __init__(self, message): 20 | super().__init__(message) 21 | -------------------------------------------------------------------------------- /utils/logger.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import os 3 | 4 | log = logging.getLogger("nvidia-bot") 5 | log.setLevel(logging.DEBUG) 6 | 7 | file_log_handler = logging.FileHandler("nvidia-bot.log") 8 | file_log_handler.setFormatter( 9 | logging.Formatter('%(levelname)s: "%(asctime)s - %(message)s') 10 | ) 11 | file_log_handler.setLevel(logging.DEBUG) 12 | 13 | 14 | LOGLEVEL = os.environ.get("LOGLEVEL", "INFO").upper() 15 | stream_handler = logging.StreamHandler() 16 | stream_handler.setFormatter( 17 | logging.Formatter('%(levelname)s: "%(asctime)s - %(message)s') 18 | ) 19 | stream_handler.setLevel(LOGLEVEL) 20 | 21 | log.addHandler(stream_handler) 22 | log.addHandler(file_log_handler) 23 | -------------------------------------------------------------------------------- /utils/selenium_utils.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from selenium.webdriver.chrome.options import Options 3 | from selenium.webdriver.common.action_chains import ActionChains 4 | from selenium.webdriver.common.by import By 5 | from selenium.webdriver.support import expected_conditions as ec 6 | from selenium.webdriver.support.wait import WebDriverWait 7 | 8 | 9 | options = Options() 10 | options.add_experimental_option("excludeSwitches", ["enable-automation"]) 11 | options.add_experimental_option("useAutomationExtension", False) 12 | 13 | 14 | class AnyEc: 15 | """Use with WebDriverWait to combine expected_conditions 16 | in an OR. 17 | """ 18 | 19 | def __init__(self, *args): 20 | self.ecs = args 21 | 22 | def __call__(self, driver): 23 | for fn in self.ecs: 24 | try: 25 | if fn(driver): 26 | return True 27 | except: 28 | pass 29 | 30 | 31 | def no_amazon_image(): 32 | prefs = {"profile.managed_default_content_settings.images": 2} 33 | options.add_experimental_option("prefs", prefs) 34 | 35 | 36 | def wait_for_element(d, e_id, time=30): 37 | """ 38 | Uses webdriver(d) to wait for page title(title) to become visible 39 | """ 40 | return WebDriverWait(d, time).until(ec.presence_of_element_located((By.ID, e_id))) 41 | 42 | 43 | def wait_for_element_by_xpath(d, e_path, time=30): 44 | return WebDriverWait(d, time).until( 45 | ec.presence_of_element_located((By.XPATH, e_path)) 46 | ) 47 | 48 | 49 | def wait_for_element_by_class(d, e_class, time=30): 50 | """ 51 | Uses webdriver(d) to wait for page title(title) to become visible 52 | """ 53 | return WebDriverWait(d, time).until( 54 | ec.presence_of_element_located((By.CLASS_NAME, e_class)) 55 | ) 56 | 57 | 58 | def wait_for_title(d, title, path): 59 | """ 60 | Uses webdriver(d) to navigate to get(path) until it equals title(title) 61 | """ 62 | while d.title != title: 63 | d.get(path) 64 | WebDriverWait(d, 1000) 65 | 66 | 67 | def wait_for_page(d, title, time=30): 68 | """ 69 | Uses webdriver(d) to wait for page title(title) to become visible 70 | """ 71 | WebDriverWait(d, time).until(ec.title_is(title)) 72 | 73 | 74 | def wait_for_either_title(d, title1, title2, time=30): 75 | """ 76 | Uses webdriver(d) to wait for page title(title1 or title2) to become visible 77 | """ 78 | try: 79 | WebDriverWait(d, time).until(AnyEc(ec.title_is(title1), ec.title_is(title2))) 80 | except Exception: 81 | pass 82 | 83 | 84 | def wait_for_any_title(d, titles, time=30): 85 | """ 86 | Uses webdriver(d) to wait for page title(title1 or title2) to become visible 87 | """ 88 | my_args_list = [] 89 | for title in titles: 90 | my_args_list.append(ec.title_is(title)) 91 | 92 | WebDriverWait(d, time).until(AnyEc(*my_args_list)) 93 | 94 | 95 | def button_click_using_xpath(d, xpath): 96 | """ 97 | Uses webdriver(d) to click a button using an XPath(xpath) 98 | """ 99 | button_menu = WebDriverWait(d, 10).until( 100 | ec.element_to_be_clickable((By.XPATH, xpath)) 101 | ) 102 | action = ActionChains(d) 103 | action.move_to_element(button_menu).pause(1).click().perform() 104 | 105 | 106 | def field_send_keys(d, field, keys): 107 | """ 108 | Uses webdriver(d) to fiend a field(field), clears it and sends keys(keys) 109 | """ 110 | elem = d.find_element_by_name(field) 111 | elem.clear() 112 | elem.send_keys(keys) 113 | 114 | 115 | def has_class(element, class_name): 116 | classes = element.get_attribute("class") 117 | 118 | return class_name in classes 119 | 120 | 121 | def add_cookies_to_session_from_driver(driver, session): 122 | cookies = driver.get_cookies() 123 | 124 | [ 125 | session.cookies.set_cookie( 126 | requests.cookies.create_cookie( 127 | domain=cookie["domain"], 128 | name=cookie["name"], 129 | value=cookie["value"], 130 | ) 131 | ) 132 | for cookie in cookies 133 | ] 134 | 135 | 136 | def enable_headless(): 137 | options.add_argument("--headless") 138 | options.add_argument("--no-sandbox") 139 | options.add_argument("--disable-dev-shm-usage") 140 | --------------------------------------------------------------------------------