forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
[pull] master from avinashkranjan:master #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
92d1043
Merge pull request #1 from avinashkranjan/master
anuragmukherjee2001 394435b
Create mini google assistant.py
A-kriti 4ee89b3
Create mini google assistant.py
A-kriti ff6afd0
Create README.md
A-kriti 0943ea1
Add GUI Chat Application
Yuvraj-kadale e03f323
Added the health log book
anuragmukherjee2001 3de0844
Updated the README file
anuragmukherjee2001 d18e30d
Add initial files
Lakhankumawat 55454e0
Add brick game
Yuvraj-kadale f4e9393
Updating the main.py file
anuragmukherjee2001 b2c02d4
Creating database.py file
anuragmukherjee2001 a3db397
Updated the README file
anuragmukherjee2001 cb892a9
Fix GUI Chat additional files
Yuvraj-kadale eca9975
fix bugs
Yuvraj-kadale 24101b7
Add Readme
Yuvraj-kadale de93854
Add Output
Yuvraj-kadale 243f854
Update Brick Breaker game/Readme.md
Yuvraj-kadale ae9584e
This is my code for issue
shantamsultania a36439d
Add click to start
Yuvraj-kadale bb2e590
Merge branch 'brick_game' of https://github.com/Yuvraj-kadale/Amazing...
Yuvraj-kadale 54da987
AWS Scripts for Automation's
shantamsultania da2d538
Update TicTacToe.py
Lakhankumawat 57b408f
Update TicTacToe.py
Lakhankumawat 02262e4
AWS Automation Script for creating/ Managing Aws Ec2 instances and RDS
shantamsultania 0049b68
AWS Automation testing scripts for AWS Code testing
shantamsultania 5a4a628
Create Fast_Algorithm.py
ShubhamGupta577 7b9be77
Add files via upload
ShubhamGupta577 293d6d4
Create Readme.md
ShubhamGupta577 ed3b65f
Delete mini google assistant.py
A-kriti 8a5364b
Create script.py
tanvi355 92b7af9
Create README.md
tanvi355 54351b9
Update Fast Algorithm/Fast_Algorithm.py
ShubhamGupta577 2beb21e
Requested changes done.
ShubhamGupta577 361c1a1
Adding guessing game with tkinter code and readme
saidrishya 5d7b8d7
Rename Fast Algorithm/Fast_Algorithm.py to Fast Algorithm (Corner Det...
ShubhamGupta577 9df4db3
Rename Fast Algorithm/Readme.md to Fast Algorithm (Corner Detection)/...
ShubhamGupta577 98cb4da
Add files via upload
ShubhamGupta577 e9cea75
Delete Fast Algorithm directory
ShubhamGupta577 dff871e
Update Readme.md
ShubhamGupta577 1bd944e
Update Fast_Algorithm.py
ShubhamGupta577 31de4f7
scraping implemented
Ayushjain2205 536ff6f
display script added - to display data from database
Ayushjain2205 dad4ae2
requirements file added
Ayushjain2205 c1fbc98
save scraped data in database
Ayushjain2205 338179b
Readme file added
Ayushjain2205 86f195c
Updated The main.py file
anuragmukherjee2001 3afaecf
Update TicTacToe.py
Lakhankumawat 2c84829
Add game over screen
Yuvraj-kadale 15facfe
fix indentation
Yuvraj-kadale 5eb1e2a
Create Mini google assistant.py
A-kriti d7940af
AWS Management Scripts
shantamsultania 060cb2a
AWS Management Scripts
shantamsultania 7f479f5
Requested changes have been made.
ShubhamGupta577 9142f41
Update README.md
tanvi355 a4bce14
Update AWS Management Scripts/AWS Automation Script for AWS endorseme...
shantamsultania 0fd9a3b
Update AWS Management Scripts/AWS Automation Script for AWS endorseme...
shantamsultania c7fd39a
Update AWS Management Scripts/AWS Automation Script for AWS endorseme...
shantamsultania c24d1c6
Delete mini google assistant.py
A-kriti 00b9082
changes made
Ayushjain2205 268c0ef
AWS Management Scripts
shantamsultania 2e0412a
Merge remote-tracking branch 'origin/master'
shantamsultania ff899a4
Requested Changes Made
Lakhankumawat cface0d
Merge pull request #899 from Ayushjain2205/udemy-scraper
avinashkranjan 8ab0997
Merge pull request #897 from saidrishya/new_branch
avinashkranjan 157980f
Merge pull request #895 from tanvi355/random_password
avinashkranjan b7de81c
Merge pull request #889 from shantamsultania/master
avinashkranjan 1abec10
Merge pull request #880 from A-kriti/mini-google-assistant-1
avinashkranjan da0e6ed
Merge pull request #854 from Yuvraj-kadale/brick_game
avinashkranjan b7662b9
Merge pull request #851 from Lakhankumawat/TicTacToe-GUI
avinashkranjan dc12e6a
Merge pull request #891 from ShubhamGupta577/Fast-Algorithm
avinashkranjan 3f0dd7a
Merge pull request #830 from anuragmukherjee2001/health_log_book
avinashkranjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
...nagement Scripts/AWS Automation Script for AWS endorsement management/Readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## Aws Script for AWS Management | ||
|
||
This python script can be used to manage a AWS endorsement. | ||
|
||
This provides features like : | ||
|
||
### EC2 : | ||
|
||
1. Create your own Key based SnapShots | ||
2. Delete SnapShots | ||
3. Delete/ Terminate any EC2 instance which does not have a user/ any specific tag | ||
4. stop any useless Running Ec2 instance | ||
|
||
### RDS : | ||
|
||
1. delete RDS Instance | ||
2. Delete RDS Cluster | ||
3. Stop any useless Running RDS Cluster/Instance | ||
4. Delete useless Snapshots | ||
5. Delete any RDS Instance or Cluster which does not have a specific tag with it | ||
6. Delete any RDS Snapshot that is older then 2 days | ||
|
||
these Scripts can directly be used with AWS lambda function for Automation purposes as well | ||
|
||
## Installation | ||
|
||
First of all install [python]("https://www.python.org/downloads/") on your system. | ||
``` | ||
pip install boto3 | ||
``` | ||
|
||
### Made with ❤️ by Shantam Sultania | ||
|
||
You can find me at:- | ||
[Linkedin](https://www.linkedin.com/in/shantam-sultania-737084175/) or [Github](https://github.com/shantamsultania) . | ||
|
||
Happy coding ❤️ . |
17 changes: 17 additions & 0 deletions
AWS Management Scripts/AWS Automation Script for AWS endorsement management/awsLambda.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
def lambda_handler(event, context): | ||
print("event " + str(event)) | ||
print("context " + str(context)) | ||
ec2_reg = boto3.client('ec2') | ||
regions = ec2_reg.describe_regions() | ||
for region in regions['Regions']: | ||
region_name = region['RegionName'] | ||
instances = Ec2Instances(region_name) | ||
deleted_counts = instances.delete_snapshots(1) | ||
instances.delete_available_volumes() | ||
print("deleted_counts for region " + str(region_name) + " is " + str(deleted_counts)) | ||
instances.shutdown() | ||
print("For RDS") | ||
rds = Rds(region_name) | ||
rds.cleanup_snapshot() | ||
rds.cleanup_instances() | ||
return 'Hello from Lambda' |
98 changes: 98 additions & 0 deletions
AWS Management Scripts/AWS Automation Script for AWS endorsement management/ec2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
from datetime import datetime, timedelta, timezone | ||
|
||
import boto3 | ||
|
||
|
||
def get_delete_data(older_days): | ||
delete_time = datetime.now(tz=timezone.utc) - timedelta(days=older_days) | ||
return delete_time; | ||
|
||
|
||
def is_ignore_shutdown(tags): | ||
for tag in tags: | ||
print("K " + str(tag['Key']) + " is " + str(tag['Value'])) | ||
if str(tag['Key']) == 'excludepower' and str(tag['Value']) == 'true': | ||
print("Not stopping K " + str(tag['Key']) + " is " + str(tag['Value'])) | ||
return True | ||
return False | ||
|
||
|
||
def is_unassigned(tags): | ||
if 'user' not in [t['Key'] for t in tags]: | ||
return True | ||
return False | ||
|
||
|
||
class Ec2Instances(object): | ||
|
||
def __init__(self, region): | ||
print("region " + region) | ||
|
||
# if you are not using AWS Tool Kit tool you will be needing to pass your access key and secret key here | ||
|
||
# client = boto3.client('rds', region_name=region_name, aws_access_key_id=aws_access_key_id, | ||
# aws_secret_access_key=aws_secret_access_key) | ||
self.ec2 = boto3.client('ec2', region_name=region) | ||
|
||
def delete_snapshots(self, older_days=2): | ||
delete_snapshots_num = 0 | ||
snapshots = self.get_nimesa_created_snapshots() | ||
for snapshot in snapshots['Snapshots']: | ||
fmt_start_time = snapshot['StartTime'] | ||
if fmt_start_time < get_delete_data(older_days): | ||
try: | ||
self.delete_snapshot(snapshot['SnapshotId']) | ||
delete_snapshots_num + 1 | ||
except Exception as e: | ||
print(e) | ||
return delete_snapshots_num | ||
|
||
def get_user_created_snapshots(self): | ||
snapshots = self.ec2.describe_snapshots( | ||
Filters=[{ | ||
'Name': 'owner-id', 'Values': ['your owner id'], | ||
}]) # Filters=[{'Name': 'description', 'Values': ['Created by Nimesa']}] | ||
return snapshots | ||
|
||
def delete_available_volumes(self): | ||
volumes = self.ec2.describe_volumes()['Volumes'] | ||
for volume in volumes: | ||
if volume['State'] == "available": | ||
self.ec2.delete_volume(VolumeId=volume['VolumeId']) | ||
|
||
def delete_snapshot(self, snapshot_id): | ||
self.ec2.delete_snapshot(SnapshotId=snapshot_id) | ||
|
||
def shutdown(self): | ||
instances = self.ec2.describe_instances() | ||
instance_to_stop = [] | ||
instance_to_terminate = [] | ||
for res in instances['Reservations']: | ||
for instance in res['Instances']: | ||
tags = instance.get('Tags') | ||
if tags is None: | ||
instance_to_terminate.append(instance['InstanceId']) | ||
continue | ||
if is_unassigned(tags): | ||
print("instance_to_terminate " + instance['InstanceId']) | ||
instance_to_terminate.append(instance['InstanceId']) | ||
if is_ignore_shutdown(tags): | ||
continue | ||
if instance['State']['Code'] == 16: | ||
instance_to_stop.append(instance['InstanceId']) | ||
|
||
if any(instance_to_stop): | ||
self.ec2.stop_instances( | ||
InstanceIds=instance_to_stop | ||
) | ||
if any(instance_to_terminate): | ||
print(instance_to_terminate) | ||
self.ec2.terminate_instances( | ||
InstanceIds=instance_to_terminate | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
ec2 = Ec2Instances('us-east-1') | ||
ec2.delete_snapshots(3) | ||
ec2.shutdown() |
132 changes: 132 additions & 0 deletions
AWS Management Scripts/AWS Automation Script for AWS endorsement management/rds.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import boto3 | ||
import datetime | ||
|
||
|
||
class Rds(object): | ||
|
||
def __init__(self, region) -> None: | ||
super().__init__() | ||
self.rds = boto3.client('rds', region) | ||
|
||
def cleanup_snapshot(self): | ||
self._cleanup_snapshot_instance() | ||
self._cleanup_snapshots_clusters() | ||
|
||
def cleanup_instances(self): | ||
clusters = self.rds.describe_db_clusters() | ||
for cluster in clusters['DBClusters']: | ||
self._cleanup_cluster(cluster) | ||
instances = self.rds.describe_db_instances() | ||
for instance in instances['DBInstances']: | ||
self._cleanup_instance(instance) | ||
|
||
def _stop_cluster(self, identifier): | ||
self.rds.stop_db_cluster(DBClusterIdentifier=identifier) | ||
|
||
def _stop_instance(self, identifier): | ||
self.rds.stop_db_instance(DBInstanceIdentifier=identifier) | ||
|
||
def _delete_instance(self, identifier): | ||
self.rds.describe_db_instances(DBInstanceIdentifier=identifier) | ||
|
||
def _delete_cluster(self, identifier): | ||
self.rds.describe_db_clusters(DBClusterIdentifier=identifier) | ||
|
||
def _delete_instance_snapshot(self, identifier): | ||
self.rds.delete_db_snapshot(DBSnapshotIdentifier=identifier) | ||
|
||
def _delete_cluster_snapshot(self, identifier): | ||
self.rds.delete_db_cluster_snapshot(DBClusterSnapshotIdentifier=identifier) | ||
|
||
@staticmethod | ||
def _can_delete_instance(tags): | ||
if any('user' in tag for tag in tags): | ||
return False | ||
|
||
@staticmethod | ||
def _can_stop_instance(tags): | ||
for tag in tags: | ||
if tag["Key"].lower() == 'excludepower' and tag['Value'].lower() == 'true': | ||
return False | ||
return True | ||
|
||
@staticmethod | ||
def _can_delete_snapshot(tags): | ||
if tags is not None: | ||
for tag in tags: | ||
if tag['Key'].lower() == 'retain' and tag['Value'].lower() == 'true': | ||
return False | ||
return True | ||
|
||
def _cleanup_instance(self, instance): | ||
identifier = instance['DBInstanceIdentifier'] | ||
tags = instance['TagList'] | ||
if self._can_delete_instance(tags): | ||
self._delete_instance(identifier) | ||
else: | ||
if self._can_stop_instance(tags) and instance['DBInstanceStatus'] == 'available': | ||
try: | ||
self._stop_instance(identifier) | ||
except Exception as e: | ||
print(str(e)) | ||
|
||
def _cleanup_cluster(self, cluster): | ||
tags = cluster['TagList'] | ||
if self._can_delete_instance(tags): | ||
self._delete_cluster(cluster['DBClusterIdentifier']) | ||
else: | ||
if self._can_stop_instance(tags) and cluster['Status'] == 'available': | ||
try: | ||
self._stop_cluster(cluster['DBClusterIdentifier']) | ||
except Exception as e: | ||
print(str(e)) | ||
|
||
def _cleanup_snapshots_clusters(self): | ||
snapshots = self.rds.describe_db_cluster_snapshots() | ||
for snapshot in snapshots['DBClusterSnapshots']: | ||
tags = snapshot['TagList'] | ||
if self._can_delete_snapshot(tags) and self._is_older_snapshot( | ||
str(snapshot['SnapshotCreateTime']).split(" ")): | ||
try: | ||
self._delete_cluster_snapshot(snapshot['DBClusterSnapshotIdentifier']) | ||
except Exception as e: | ||
print(str(e)) | ||
|
||
def _cleanup_snapshot_instance(self): | ||
snapshots = self.rds.describe_db_snapshots() | ||
for snapshot in snapshots['DBSnapshots']: | ||
tags = snapshot['TagList'] | ||
if self._can_delete_snapshot(tags) and self._is_older_snapshot( | ||
str(snapshot['SnapshotCreateTime']).split(" ")): | ||
try: | ||
self._delete_instance_snapshot(snapshot['DBSnapshotIdentifier']) | ||
except Exception as e: | ||
print(str(e)) | ||
|
||
@staticmethod | ||
def _is_older_snapshot(snapshot_datetime): | ||
snapshot_date = snapshot_datetime[0].split("-") | ||
snapshot_date = datetime.date(int(snapshot_date[0]), int(snapshot_date[1]), int(snapshot_date[2])) | ||
today = datetime.date.today() | ||
if abs(today - snapshot_date).days > 2: | ||
return True | ||
else: | ||
return False | ||
|
||
@staticmethod | ||
def _check_snapshot_tag(tags): | ||
flag = False | ||
for tag in tags: | ||
if tag['Key'].lower() == 'retain' and tag['Value'].lower() == 'true': | ||
flag = True | ||
if flag: | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
if __name__ == "__main__": | ||
rds = Rds('us-east-1') | ||
# # rds.shutdown() | ||
rds.cleanup_snapshot() | ||
rds.cleanup_instances() |
29 changes: 29 additions & 0 deletions
AWS Management Scripts/AWS testing Script/Readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## Aws Script for testing using moto (a AWS testing framework ) | ||
|
||
This python script automatically generates a set of EC2 machine's with any demo ami Id that could be used in case of testing. | ||
|
||
## Installation | ||
|
||
First of all install [python]("https://www.python.org/downloads/") on your system. | ||
```bash | ||
pip install moto | ||
pip install boto3 | ||
pip install Flask | ||
``` | ||
|
||
## Results | ||
|
||
 | ||
|
||
 | ||
|
||
 | ||
|
||
### Made with ❤️ by Shantam Sultania | ||
|
||
You can find me at:- | ||
[Linkedin](https://www.linkedin.com/in/shantam-sultania-737084175/) or [Github](https://github.com/shantamsultania) . | ||
|
||
Happy coding ❤️ . | ||
|
||
|
33 changes: 33 additions & 0 deletions
AWS Management Scripts/AWS testing Script/agentMain.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from flask import Flask | ||
from flask_ngrok import run_with_ngrok | ||
import awstesting.awsTester as aws_testing | ||
|
||
app = Flask(__name__) | ||
|
||
# run_with_ngrok(app) | ||
|
||
|
||
@app.route("/", methods=['POST', 'GET']) | ||
def welcome(): | ||
message = "Welcome to create your own test Api for AWS for Ec2 just use your Url/ec2 and your 100 ec2 " \ | ||
"instance will be created in test environment if you dont want to use it in api based " \ | ||
"just go to code and use awsTesting class and done " | ||
return message | ||
|
||
|
||
# this api is to create an ec2 for testing | ||
|
||
@app.route("/ec2", methods=['POST', 'GET']) | ||
def ec2(): | ||
client = aws_testing.add_service("ec2", "us-east-1") | ||
return aws_testing.test_create_ec2(client) | ||
|
||
|
||
# you can add more apis of your choice here like | ||
# create Volume, VPC and snapshots | ||
|
||
# to do so just add a call function in awsTester class and agentMain and you are done | ||
|
||
# run the app | ||
if __name__ == '__main__': | ||
app.run() |
15 changes: 15 additions & 0 deletions
AWS Management Scripts/AWS testing Script/awsHandler.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
def create_ec2(client, ami_id, count): | ||
client.run_instances(ImageId=ami_id, MinCount=count, MaxCount=count) | ||
|
||
|
||
def create_ec2_snapshots(client, volume_id): | ||
client.create_snapshot(VolumeId=volume_id) | ||
|
||
|
||
def create_ec2_volume(client, AZ): | ||
ab = client.create_volume(AZ) | ||
return ab | ||
|
||
|
||
def create_vpc(client, cidr_block): | ||
client.create_vpc(CidrBlock=cidr_block) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.