Example #1
0
def load_techs():
    global techs
    techs = {}

    tech_list = generic_load("techs.dat")

    for tech_name in tech_list:

        # Certain keys are absolutely required for each entry.  Make sure
        # they're there.
        check_required_fields(tech_name, ("id", "cost"), "Tech")

        # Get the costs.
        cost_list = tech_name["cost"]
        if type(cost_list) != list or len(cost_list) != 3:
            sys.stderr.write("Error with cost given: %s" % repr(cost_list))
            sys.exit(1)

        tech_cost = [int(x) for x in cost_list]

        # Make sure prerequisites, if any, are lists.
        tech_pre = tech_name.get("pre", [])
        if type(tech_pre) != list:
            tech_pre = [tech_pre]

        if tech_name.has_key("danger"):
            tech_danger = int(tech_name["danger"])
        else:
            tech_danger = 0

        if tech_name.has_key("type"):

            type_list = tech_name["type"]
            if type(type_list) != list or len(type_list) != 2:
                sys.stderr.write("Error with type given: %s\n" % repr(type_list))
                sys.exit(1)
            tech_type = type_list[0]
            tech_second = int(type_list[1])
        else:
            tech_type = ""
            tech_second = 0

        techs[tech_name["id"]]=tech.Tech(tech_name["id"], "", 0,
         tech_cost, tech_pre, tech_danger, tech_type, tech_second)

    if debug: print "Loaded %d techs." % len (techs)

    load_tech_defs()
Example #2
0
def load_techs():
    global techs
    techs = {}

    tech_list = generic_load("techs.dat")

    for tech_name in tech_list:

        # Certain keys are absolutely required for each entry.  Make sure
        # they're there.
        check_required_fields(tech_name, ("id", "cost"), "Tech")

        # Get the costs.
        cost_list = tech_name["cost"]
        if type(cost_list) != list or len(cost_list) != 3:
            sys.stderr.write("Error with cost given: %s" % repr(cost_list))
            sys.exit(1)

        tech_cost = [int(x) for x in cost_list]

        # Make sure prerequisites, if any, are lists.
        tech_pre = tech_name.get("pre", [])
        if type(tech_pre) != list:
            tech_pre = [tech_pre]

        if tech_name.has_key("danger"):
            tech_danger = int(tech_name["danger"])
        else:
            tech_danger = 0

        if tech_name.has_key("type"):

            type_list = tech_name["type"]
            if type(type_list) != list or len(type_list) != 2:
                sys.stderr.write("Error with type given: %s\n" %
                                 repr(type_list))
                sys.exit(1)
            tech_type = type_list[0]
            tech_second = int(type_list[1])
        else:
            tech_type = ""
            tech_second = 0

        techs[tech_name["id"]] = tech.Tech(tech_name["id"], "", 0, tech_cost,
                                           tech_pre, tech_danger, tech_type,
                                           tech_second)

    # As with others, we load the en_US language definitions as a safe
    # default, then overwrite them with the selected language.

    load_tech_defs("en_US")
    if language != "en_US":
        load_tech_defs(language)


# #        techs["Construction 1"] = tech.Tech("Construction 1",
# #                "Basic construction techniques. "+
# #                "By studying the current literature on construction techniques, I "+
# #                "can learn to construct basic devices.",
# #                0, (5000, 750, 0), [], 0, "", 0)

    if debug:
        print "Loaded %d techs." % len(techs)
Example #3
0
            qustion = (section.find("div", "excerpt")).text

            qId = href.rsplit('/', 2)[1]

            tags = []
            tagesArraytempIndex = 0
            tagesArraytemp = (section.find_all("a", "post-tag"))
            for tagesArraytempIndex in tagesArraytemp:
                tags.append(tagesArraytempIndex.text)

            if (year != "none"):
                if (int(year) < 2013):
                    break
                else:
                    if (year != openendFileName):
                        sys.stdout.close()
                        ### open Data 1 file all STDOUT data are printed to the file
                        sys.stdout = open("./data/" + year + ".json", "a")
                    techObject = tech.Tech(source, header, qustion, tags, qId,
                                           year, href)
                    techArray.append(techObject)
                    json_string = json.dumps(techObject.__dict__)
                    print(json_string)

# sys.stdout.close()

#sys.stdout = open("Data1.json", "a")
#json_string = json.dumps([ob.__dict__ for ob in techArray])
#print(json_string)
Example #4
0
 def setUp(self):
     self._loop = asyncio.get_event_loop()
     self._session = aiohttp.ClientSession(loop=self._loop)
     self._tech = tech.Tech(self._session)
     self._loop.run_until_complete(
         self._tech.authenticate("email", "password"))
Example #5
0
            #print(relativeTime)

            qustion = (section.find("div", "excerpt")).text
            #print(qustion)

            qId = href.rsplit('/', 2)[1]
            #print(qId)

            tags = []
            tagesArraytempIndex = 0
            tagesArraytemp = (section.find_all("a", "post-tag"))
            for tagesArraytempIndex in tagesArraytemp:
                tags.append(tagesArraytempIndex.text)
            #print(tags)

            techObject = tech.Tech(header, qustion, tags, qId, relativeTime,
                                   href)
            techArray.append(techObject)

            json_string = json.dumps(techObject.__dict__)
            print(json_string)
            ##print('-------------------------------------------------------------------')

#run now

#print('----')
#print (techArray)

#sys.stdout = open("Data1.json", "w+")
#for a in techArray:
# print(a)
# json.dumps(a)