예제 #1
0
def removePairingFromFile(pair):
	lines = []
	with getFile("remaining_pairings.txt", "r") as file:
		lines = file.read().splitlines()

	lines.remove(pair)

	with getFile("remaining_pairings.txt", "w") as file:
		for line in lines:
			file.write(line + "\n")

	return
예제 #2
0
def addPostHistory(entry):
	with getFile("config.yml", "r") as file:
		config = safe_load(file)

	# for first run, should be a better way to do this 
	if(config["posthistory"] == None):
		config["posthistory"] = {}

	config["posthistory"][getCurrentPostNumber()] = entry

	with getFile("config.yml", "w") as file:
		dump(config, file)

	return
예제 #3
0
def generatePrevPostSection():
	postHistory = getPostHistory()

	if(postHistory == {}):
		return ""
	else:
		with getFile("Reddit Post Templates/previousPostSectionTemplate.md") as prevPostSectionFile, \
			 getFile("Reddit Post Templates/previousPostTemplate.md") as prevPostFile:

			prevPostSectTemplate = prevPostSectionFile.read()
			prevPostTemplate = prevPostFile.read()

			prevPostSectText = ""
			for postNumber, details in take(5, reversed(postHistory.items())):
				prevPostSectText += prevPostTemplate.format(postNumber, **details) + "\n"

			return prevPostSectTemplate.format(prevPostSectText)
예제 #4
0
def getAllCommanders():
	global commanders
	if(commanders):
		return commanders

	with getFile("config.yml") as file:
		for commander, details in safe_load(file)["commanders"].items():
			commanders.append(Commander(commander, details))
			
	return commanders
예제 #5
0
    def __init__(self, name, details=None):
        self.name = name

        # get details from config if not supplied
        if (details == None):
            with getFile("config.yml", "r") as file:
                details = safe_load(file)["commanders"][name]

        self.race = details["race"]
        self.date = details["date"]
        self.prettydate = self.date.strftime("%b %d %Y")
        self.sc2cooplink = details["sc2cooplink"]
        self.wikilink = details["wikilink"]
예제 #6
0
def getRedditInstance():
    global reddit

    if (reddit):
        return reddit

    with getFile("credentials.yml") as file:
        credentials = safe_load(file)["reddit"]

    reddit = praw.Reddit(**credentials)
    reddit.validate_on_submit = True

    return reddit
예제 #7
0
def getCSV():
    return getFile("csv")
예제 #8
0
def getTemplate():
    return getFile("template")
예제 #9
0
import re
from sch_utils import findComponentsLines, getComponent, extracValues, GetLCSC
from file_handler import getFile, appendInfoToFile, save, filename
from search import SearchLCSC
from term_utils import clear

comp = findComponentsLines(getFile())
acc = 0
""" _dat = getFile().readlines()
for i, el in enumerate(comp):
    _dat = appendInfoToFile(_dat, el + i, "ola\n") """

# Sniffeo todos los componentes y busco si tienen el codigo de LCSC
skipped = 0
noVal = 0

for i, el in enumerate(comp):
    _comp = getComponent(getFile(), el)
    LCSC = GetLCSC(_comp)
    if LCSC:
        print(
            f"Found component on line {el} ,component: {_comp} with LCSC code, skipping"
        )
        skipped += 1
    else:
        _searchComp = SearchLCSC(_comp)
        line = _comp[len(_comp) - 1][0] + acc
        if _searchComp != "null":
            print(
                f"vamo a imprimir en la linea {line} el valor: {_searchComp}")
            _dat = getFile().readlines()
예제 #10
0
def getRemainingPairings():
	with getFile("remaining_pairings.txt") as file:
		# readlines() includes the \n :facepalm:
		#return file.readlines()
		return file.read().splitlines()
예제 #11
0
def getPostHistory():
	with getFile("config.yml", "r") as file:
		return safe_load(file)["posthistory"] or {}
예제 #12
0
def repopulatePairings():
	with getFile("remaining_pairings.txt", "w") as file:
		for pair in pg.getCompletePairings():
			file.write(str(pair[0]) + "|" + str(pair[1]) + "\n")

	return
예제 #13
0
			return prevPostSectTemplate.format(prevPostSectText)

if(__name__ == '__main__'):
	today = datetime.date.today()
	if(today.weekday() == 2):
		pairings = getRemainingPairings()

		if(len(pairings) == 0):
			repopulatePairings()
			pairings = getRemainingPairings()

		pair = random.choice(pairings)
		commander_pair = convertStrToCommanderPair(pair)

		with getFile("Reddit Post Templates/mainTemplate.md") as mainFile, \
			 getFile("Reddit Post Templates/commanderTemplate.md") as commanderFile, \
			 getFile("Reddit Post Templates/titleTemplate.md") as titleFile:

			mainTemplate = mainFile.read()
			commanderTemplate = commanderFile.read()
			titleTemplate = titleFile.read()

		prevPostSect = generatePrevPostSection()

		title = titleTemplate.format(postnumber = getCurrentPostNumber(), commander1 = commander_pair[0].name, commander2 = commander_pair[1].name)
		text = mainTemplate.format(commander1 = commanderTemplate.format(commander_pair[0]), commander2 = commanderTemplate.format(commander_pair[1]), prevPostSect = prevPostSect)

		postID = getSubredditInstance().submit(title, selftext = text)
		
		addPostHistory(generatePostHistoryEntry(postID, pair))