Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Commit cce8274

Browse files
authored
Merge pull request #1 from Python-World/master
Updated From Original.
2 parents 68b1ffb + f27fcac commit cce8274

File tree

12 files changed

+276
-1
lines changed

12 files changed

+276
-1
lines changed

.all-contributorsrc

+9
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,15 @@
362362
"contributions": [
363363
"code"
364364
]
365+
},
366+
{
367+
"login": "SuvamPrasd",
368+
"name": "suvam prasad",
369+
"avatar_url": "https://avatars3.githubusercontent.com/u/32155332?v=4",
370+
"profile": "https://suvamprogrammer.blogspot.com",
371+
"contributions": [
372+
"code"
373+
]
365374
}
366375
],
367376
"contributorsPerLine": 7,

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com)
77

88
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
9-
[![All Contributors](https://img.shields.io/badge/all_contributors-39-orange.svg?style=flat-square)](#contributors-)
9+
[![All Contributors](https://img.shields.io/badge/all_contributors-40-orange.svg?style=flat-square)](#contributors-)
1010
<!-- ALL-CONTRIBUTORS-BADGE:END -->
1111

1212
![Issues](https://img.shields.io/github/issues/Python-World/Python_and_the_Web)
@@ -94,6 +94,7 @@ We now have a section for miscellaneous scripts as well.
9494
<td align="center"><a href="https://github.com/ShravanBhat"><img src="https://avatars3.githubusercontent.com/u/48554826?v=4" width="100px;" alt=""/><br /><sub><b>Shravan Bhat</b></sub></a><br /><a href="https://github.com/Python-World/Python_and_the_Web/commits?author=ShravanBhat" title="Code">💻</a></td>
9595
<td align="center"><a href="https://github.com/Agrover112"><img src="https://avatars3.githubusercontent.com/u/42321810?v=4" width="100px;" alt=""/><br /><sub><b>Agrover112</b></sub></a><br /><a href="https://github.com/Python-World/Python_and_the_Web/commits?author=Agrover112" title="Code">💻</a></td>
9696
<td align="center"><a href="https://github.com/ShantanuTaro"><img src="https://avatars3.githubusercontent.com/u/43516930?v=4" width="100px;" alt=""/><br /><sub><b>Shantanu Taro</b></sub></a><br /><a href="https://github.com/Python-World/Python_and_the_Web/commits?author=ShantanuTaro" title="Code">💻</a></td>
97+
<td align="center"><a href="https://suvamprogrammer.blogspot.com"><img src="https://avatars3.githubusercontent.com/u/32155332?v=4" width="100px;" alt=""/><br /><sub><b>suvam prasad</b></sub></a><br /><a href="https://github.com/Python-World/Python_and_the_Web/commits?author=SuvamPrasd" title="Code">💻</a></td>
9798
</tr>
9899
</table>
99100

Scripts/Bots/Twitter_bot/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# TWITTER BOT
2+
<!--Remove the below lines and add yours -->
3+
This is a twitter bot, it will like and retweet your tweet, containing some keyword and will print the url of tweet.
4+
5+
### Prerequisites
6+
<!--Remove the below lines and add yours -->
7+
To install twython
8+
```pip install twython```
9+
or check [here](https://twython.readthedocs.io/en/latest/usage/install.html)
10+
<br>
11+
To install configparser
12+
```pip install configparser```
13+
or check [here](https://pypi.org/project/configparser/)
14+
<br>
15+
Generate your unique Twitter keys and token from [here](https://developer.twitter.com/en), create a new app and generate your own keys and token.
16+
17+
### How to run the script
18+
<!--Remove the below lines and add yours -->
19+
Update the keys and tokens in cofig.ini file(without quotes)
20+
<br>
21+
Run the python file and enter the keyword you want to track, now any new tweet will automatically liked and retweeted.
22+
It will print the link of tweet<br>
23+
24+
### Screenshot/GIF showing the sample use of the script
25+
<!--Remove the below lines and add yours -->
26+
![Editor view](https://github.com/Mysterious-Owl/Python_and_the_Web/blob/Mysterious-Owl-twitter/Scripts/Bots/Twitter_bot/images/Screenshot%201.png)
27+
![Twitter view](https://github.com/Mysterious-Owl/Python_and_the_Web/blob/Mysterious-Owl-twitter/Scripts/Bots/Twitter_bot/images/Screenshot%202.png)
28+
29+
## *Author Name*
30+
<!--Remove the below lines and add yours -->
31+
[Mysterious-Owl](https://github.com/Mysterious-Owl)
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from twython import Twython
2+
from twython import TwythonStreamer
3+
import configparser
4+
class MyStreamer(TwythonStreamer):
5+
def on_success(self, data):
6+
if 'text' in data:
7+
a=data['text'].lower()
8+
username=data['user']['screen_name']
9+
id=data['id']
10+
st.create_favorite(id=id)
11+
#change 'nice tweet' too your desired retweet reply
12+
st.update_status(status='Nice Tweet @'+username, in_reply_to_status_id=id)
13+
print("https://twitter.com/"+ username +"/status/" + str(id))
14+
15+
#enter your unique keys and tokens in config file
16+
config = configparser.ConfigParser()
17+
config.read('config.ini')
18+
19+
api_key= config['keys']['api_key']
20+
api_secret_key=config['keys']['api_secret_key']
21+
access_token=config['keys']['access_token']
22+
access_secret_token=config['keys']['access_secret_token']
23+
24+
api=MyStreamer(api_key,api_secret_key,access_token,access_secret_token)
25+
st=Twython(api_key,api_secret_key,access_token,access_secret_token)
26+
27+
keyword=input("Enter keyword to track: ")
28+
api.statuses.filter(track=keyword)

Scripts/Bots/Twitter_bot/config.ini

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[keys]
2+
api_key=
3+
api_secret_key=
4+
access_token=
5+
access_secret_token=
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Connect 4 Game
2+
3+
:heart_eyes: **Connect Four** (also known as **Four Up**, **Plot Four**, **Find Four**, **Four in a Row**, **Four in a Line**, **Drop Four**, and **Gravitrips** in the Soviet Union) is a two-player connection board game , in which the players choose a color and then take turns dropping colored discs into a seven-column, six-row vertically suspended grid. The pieces fall straight down, occupying the lowest available space within the column. The objective of the game is to be the first to form a horizontal, vertical, or diagonal line of four of one's own discs. Connect Four is a "Solved game". The first player can always win by playing the right moves.
4+
5+
The game was first sold under the _Connect Four_ trademark by "Milton Bradley Company") in February 1974.
6+
7+
## How To Play the Game ?
8+
9+
:exclamation: **NOTE:** Play this game along with your friends
10+
11+
python3 connect4game.py
12+
13+
## ScreenShots
14+
15+
![add names](addNames.png)
16+
![gameplay](gameplay.png)
17+
18+
## Creator
19+
20+
:heart: Suvam Prasad
8.28 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
import numpy as np
2+
from tkinter import *
3+
import pygame
4+
import sys
5+
import math
6+
7+
BLACK = (33, 33, 33)
8+
GREY = (235, 235, 235)
9+
RED = (255,0,0)
10+
YELLOW = (255,255,0)
11+
12+
ROW_COUNT = 6
13+
COLUMN_COUNT = 7
14+
15+
player_names = []
16+
17+
#adding players
18+
def submit():
19+
player_names.append(player_one.get())
20+
player_names.append(player_two.get())
21+
root.destroy()
22+
23+
#creating connect 4 board 6 X 7 common board size
24+
def create_board():
25+
board = np.zeros((ROW_COUNT,COLUMN_COUNT))
26+
return board
27+
28+
def drop_piece(board, row, col, piece):
29+
board[row][col] = piece
30+
31+
def is_valid_location(board, col):
32+
return board[ROW_COUNT-1][col] == 0
33+
34+
def get_next_open_row(board, col):
35+
for r in range(ROW_COUNT):
36+
if board[r][col] == 0:
37+
return r
38+
39+
40+
def winning_move(board, piece):
41+
# Check horizontal locations for win
42+
for c in range(COLUMN_COUNT-3):
43+
for r in range(ROW_COUNT):
44+
if board[r][c] == piece and board[r][c+1] == piece and board[r][c+2] == piece and board[r][c+3] == piece:
45+
return True
46+
47+
# Check vertical locations for win
48+
for c in range(COLUMN_COUNT):
49+
for r in range(ROW_COUNT-3):
50+
if board[r][c] == piece and board[r+1][c] == piece and board[r+2][c] == piece and board[r+3][c] == piece:
51+
return True
52+
53+
# Check positively sloped diaganols
54+
for c in range(COLUMN_COUNT-3):
55+
for r in range(ROW_COUNT-3):
56+
if board[r][c] == piece and board[r+1][c+1] == piece and board[r+2][c+2] == piece and board[r+3][c+3] == piece:
57+
return True
58+
59+
# Check negatively sloped diaganols
60+
for c in range(COLUMN_COUNT-3):
61+
for r in range(3, ROW_COUNT):
62+
if board[r][c] == piece and board[r-1][c+1] == piece and board[r-2][c+2] == piece and board[r-3][c+3] == piece:
63+
return True
64+
65+
def draw_board(board):
66+
for c in range(COLUMN_COUNT):
67+
for r in range(ROW_COUNT):
68+
pygame.draw.rect(screen, BLACK, (c*SQUARESIZE, r*SQUARESIZE+SQUARESIZE, SQUARESIZE, SQUARESIZE))
69+
pygame.draw.circle(screen, GREY, (int(c*SQUARESIZE+SQUARESIZE/2), int(r*SQUARESIZE+SQUARESIZE+SQUARESIZE/2)), RADIUS)
70+
71+
for c in range(COLUMN_COUNT):
72+
for r in range(ROW_COUNT):
73+
if board[r][c] == 1:
74+
pygame.draw.circle(screen, RED, (int(c*SQUARESIZE+SQUARESIZE/2), height-int(r*SQUARESIZE+SQUARESIZE/2)), RADIUS)
75+
elif board[r][c] == 2:
76+
pygame.draw.circle(screen, YELLOW, (int(c*SQUARESIZE+SQUARESIZE/2), height-int(r*SQUARESIZE+SQUARESIZE/2)), RADIUS)
77+
pygame.display.update()
78+
79+
try:
80+
81+
root = Tk()
82+
root.resizable(0,0)
83+
player_one = StringVar(master=root)
84+
player_two = StringVar(master=root)
85+
root.geometry("500x300")
86+
root.title("Connect 4 Game")
87+
Label(master=root, text="Connect 4 Game", font=('Poppins', 30, 'normal')).place(x=80, y=20)
88+
Label(master=root, text="Enter player 1 name: ").place(x=120, y=100)
89+
Entry(master=root, textvariable = player_one,font=('calibre',10,'normal')).place(x=250, y=100)
90+
Label(master=root, text="Enter player 2 name: ").place(x=120, y=140)
91+
Entry(master=root, textvariable=player_two, font=('calibre', 10, 'normal')).place(x=250, y=140)
92+
Button(master=root, text="ADD", width=10, command=submit).place(x=210,y=190)
93+
root.mainloop()
94+
95+
if player_names[0] != '' and player_names[1] != '':
96+
97+
board = create_board()
98+
99+
game_over = False
100+
turn = 0
101+
102+
pygame.init()
103+
104+
SQUARESIZE = 100
105+
106+
width = COLUMN_COUNT * SQUARESIZE
107+
height = (ROW_COUNT+1) * SQUARESIZE
108+
109+
size = (width, height)
110+
111+
RADIUS = int(SQUARESIZE/2 - 5)
112+
113+
screen = pygame.display.set_mode(size)
114+
draw_board(board)
115+
pygame.display.update()
116+
117+
myfont = pygame.font.SysFont("monospace", 30)
118+
119+
while not game_over:
120+
121+
for event in pygame.event.get():
122+
if event.type == pygame.QUIT:
123+
sys.exit()
124+
125+
if event.type == pygame.MOUSEMOTION:
126+
pygame.draw.rect(screen, GREY, (0,0, width, SQUARESIZE))
127+
posx = event.pos[0]
128+
if turn == 0:
129+
pygame.draw.circle(screen, RED, (posx, int(SQUARESIZE/2)), RADIUS)
130+
else:
131+
pygame.draw.circle(screen, YELLOW, (posx, int(SQUARESIZE/2)), RADIUS)
132+
pygame.display.update()
133+
134+
if event.type == pygame.MOUSEBUTTONDOWN:
135+
pygame.draw.rect(screen, GREY, (0,0, width, SQUARESIZE))
136+
137+
# Ask for Player 1 Input
138+
if turn == 0:
139+
posx = event.pos[0]
140+
col = int(math.floor(posx/SQUARESIZE))
141+
142+
if is_valid_location(board, col):
143+
row = get_next_open_row(board, col)
144+
drop_piece(board, row, col, 1)
145+
turn += 1
146+
turn = turn % 2
147+
148+
if winning_move(board, 1):
149+
label = myfont.render(player_names[0] + " wins the game", 1, RED)
150+
screen.blit(label, (40,10))
151+
game_over = True
152+
153+
154+
# # Ask for Player 2 Input
155+
else:
156+
posx = event.pos[0]
157+
col = int(math.floor(posx/SQUARESIZE))
158+
159+
if is_valid_location(board, col):
160+
row = get_next_open_row(board, col)
161+
drop_piece(board, row, col, 2)
162+
turn += 1
163+
turn = turn % 2
164+
165+
if winning_move(board, 2):
166+
label = myfont.render(player_names[1] + " wins the game", 1, YELLOW)
167+
screen.blit(label, (40,10))
168+
game_over = True
169+
170+
171+
draw_board(board)
172+
173+
174+
175+
if game_over:
176+
pygame.time.wait(3000)
177+
178+
except IndexError as e:
179+
print('Game closed')
18.7 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
numpy==1.19.2
2+
pygame==1.9.6

0 commit comments

Comments
 (0)