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
| import json | |
| import yaml | |
| f = open('myparamfile.json') | |
| dataParam = json.load(f) | |
| f.close() | |
| with open('mytemplatefile.yaml', 'r') as y: | |
| dataTemplate = yaml.load(y, Loader=yaml.BaseLoader) |
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
| if paramListInParamFile == paramListInTemplateFile: | |
| print ("Same parameters on both files") | |
| else: | |
| print ("Differences in parameters between both files !") | |
| resultNotInParamFile = [x for x in paramListInTemplateFile if x not in paramListInParamFile] | |
| if len(resultNotInParamFile) != 0: | |
| resultNotInParamFileStr = ' '.join(map(str, resultNotInParamFile)) | |
| print("List of keys that are not present in the param file but are in the template : " + resultNotInParamFileStr) |
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
| import requests | |
| import feedparser | |
| import json | |
| def getMediumInfo(blogPosts): | |
| # https://github.com/kurtmckee/feedparser/issues/84 | |
| import ssl | |
| if hasattr(ssl, '_create_unverified_context'): | |
| ssl._create_default_https_context = ssl._create_unverified_context |
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
| def ShareContentOnLinkedin(myposttitle, myposturl, myposttags): | |
| ######## LINKEDIN PART | |
| # First generated a client_id and a client_secret within the app page on your linkedin account | |
| # Then follow this procedure to generate a code https://medium.com/@ellesmuse/how-to-get-a-linkedin-access-token-a53f9b62f0ce | |
| # Following code will allow you to get an access token ! use only once (token as to be generated every 60 days) | |
| # code = 'xxx' |
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
| import re, sys | |
| # cron syntax "5 5 5 5 5" | |
| # Scripts vars | |
| # Crontab as python list | |
| cron = sys.argv[1] | |
| splitCron = cron.split() | |
| # Cron position | |
| positionDict = {1:"minute", 2:"hour", 3:"day", 4:"month", 5:"day of the week"} |
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
| import boto3 | |
| awsAccounts = { | |
| "Account N1": { "id": "123456789", "role": "iam-role", "region": "eu-west-3", "envs": ["env01", "env02", "env03"] }, | |
| } | |
| stsClient = boto3.client('sts') | |
| for awsAccount in awsAccounts: | |
| assumedRoleObject=stsClient.assume_role( |
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
| ec2Client = boto3.Session( | |
| region_name=awsAccounts[awsAccount]["region"], | |
| aws_access_key_id=ACCESS_KEY, | |
| aws_secret_access_key=SECRET_KEY, | |
| aws_session_token=SESSION_TOKEN | |
| ).client('ec2') | |
| for env in awsAccounts[awsAccount]['envs']: | |
| instancesByEnv[env] = {} | |
| filters = [{'Name':'tag:Name', 'Values':[env+'*']}] |
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
| dumpedInstancesByEnv = json.dumps(instancesByEnv, indent=4) | |
| f=open("/home/youruser/env_status.json", "w+") | |
| f.write(dumpedInstancesByEnv) | |
| f.close() | |
| bashprofile = open("/home/youruser/.bash_profile", "a+") | |
| bashprofileLines = bashprofile.readlines() | |
| for line in bashprofileLines: | |
| if "env_status.json" in line: | |
| print("bash_profile already sourcing env_status.json") |
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
| def display_board(board): | |
| blankBoard=""" | |
| ___________________ | |
| | | | | | |
| | 7 | 8 | 9 | | |
| | | | | | |
| |-----------------| | |
| | | | | | |
| | 4 | 5 | 6 | | |
| | | | | |
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
| import requests | |
| import json | |
| import time | |
| # Get the current position of the ISS | |
| def get_iss_current_position(): | |
| r = requests.get('http://api.open-notify.org/iss-now.json') | |
| myjson = json.loads(r.content) | |
| if myjson["message"] == "success": | |
| return myjson |
OlderNewer