Exemplo n.º 1
0
 def get(self):
     #list1Topic, list7Topic = tp.statisticTopic(board)
     list7Topic = tp.statisticTopicFast(board)
     self.popularEvents = tp.topicFreqDB(list7Topic)[:10]
     self.newEvents = tp.recommendArticle(list7Topic, 5)[:7]
    # self.newEvents = tp.randomChoice(tp.recommendArticle(list7Topic, 5), 5)
     self.render("index.html", popularEvents = self.popularEvents, newEvents = self.newEvents)
Exemplo n.º 2
0
 def get(self):
     #list1Topic, list7Topic = tp.statisticTopic(board)
     list7Topic = tp.statisticTopicFast(board)
     self.popularEvents = tp.topicFreqDB(list7Topic)[:10]
     #self.newEvents = tp.recommendArticle(list7Topic, 5)[:7]
     self.newEvents = tp.randomChoice(tp.recommendArticle(list7Topic, 5), 5)
     self.render("index.html",
                 popularEvents=self.popularEvents,
                 newEvents=self.newEvents)
Exemplo n.º 3
0
def getTopic():
    if ('i' in request.args):
        resultados = Topic.listado(int(request.args['i']))
    else:
        resultados = Topic.listado()

    if (len(resultados) == 0):
        abort(404)
    else:
        return jsonify({ 'topic': marshal(resultados, Topic.FIELDS) })
def loadManager():
    try:
        with open(constants.FILE_NAME) as json_file:
            data = json.load(json_file)
            manager = Topic.TopicsManger()
            manager.fromJson(data)
            return manager
    except Exception as e:
        print "Failed to load manager. " + str(e)
        return Topic.TopicsManger()
Exemplo n.º 5
0
    def post(self):
        json_obj = json_decode(self.request.body)
        #print 'Post data received'
        #for key in list(json_obj.keys()):
        #   print 'key: %s , value: %s' % (key, json_obj[key])
        print json_obj['key1']

        # new dictionary
        response_to_send = {}
        #response_to_send['newkey'] = json_obj['key1']
        response_to_send['topic'] = tp.topicFreqDB(tp.statisticSchoolTopic(board, json_obj['key1']))
        #print('Response to return')
        #pprint.pprint(response_to_send)

        self.write(json.dumps(response_to_send))
Exemplo n.º 6
0
	def __init__(self, GPIO, allIpPort, raspid, sensordata):
		self.tHCount = 0
		self.GPIO = GPIO
		self.brokerIpPort = allIpPort[0]
		self.cameraIpPort = allIpPort[1]

		self.all_pin = sensordata[0]
		self.adc_pin = sensordata[1]
		self.useSensor = sensordata[2]
		self.ButtonUpDown = sensordata[3]

		self.topic = Topic.Topic(self.brokerIpPort, raspid)
		self.raspid = raspid

		self.reciveControl = False
		self.sensorTimerControl = []
		self.sensorDetectControl = []
		
		self.sensorTimerControlIndex = []
		self.sensorDetectControlIndex = []

		self.sensorMoveControl = []


		self.setInstance(GPIO)
		self.receive = receive.Receive([self.sensorTimerControl, self.sensorDetectControl, self.sensorMoveControl], self.cameraIpPort, self.topic)
Exemplo n.º 7
0
    def get(self, id):
       	resultados = Topic.listado(id)

        if (len(resultados) == 0):
            abort(404)
        else:
        	return { 'topic': marshal(resultados, Topic.FIELDS) }
def addTopic():
    newTopic = Topic.Topic()
    newData = newTopic.getJsonString()
    data = loadData()
    data.append(newData)
    saveData(data)
    print "Added succesfuly"
Exemplo n.º 9
0
 def addEventToTopic(self, event):
     """
         add a event to the topic which has the most similar keywords.
     """
     # find the topic that the event belongs to
     similarity_max = 0
     index_max = -1
     for i in range(len(self.topics)):
         a = set(event.keywords)
         b = self.topics[i].keywords
         k = len(a & b)  # the number of sharing keywords
         if similarity_max < k:
             similarity_max = k
             index_max = i
     if similarity_max <= self.min_sharing_keywords_num:
         # new topic
         topic = Topic.Topic()
         topic.id = len(self.topics)
         topic.keywords = set(event.keywords)
         topic.events = [event.id]
         self.topics.append(topic)
         event.topic_id = topic.id
     else:
         self.topics[index_max].events.append(event.id)
         self.topics[index_max].keywords = self.topics[
             index_max].keywords | set(event.keywords)
         event.topic_id = self.topics[index_max].id
Exemplo n.º 10
0
	def addTopic(self, manager):
		newTopic = Topic.Topic()
		titleArg = filter(lambda argument: argument[0] == "title", self.arguments)
		if len(titleArg) > 0:
			newTopic.title = titleArg[0][1]
		else:
			 newTopic.title = "Default title"
		manager.add(newTopic)
		print ("Added topic number " + str(len(manager)))
Exemplo n.º 11
0
def searchTopic():
    searchString = raw_input("Search string? ")
    data = loadData()
    manager = Topic.TopicsManger()
    manager.fromJson(data)
    indexes = []
    for index in range(len(manager)):
        topic = manager.get(index)
        if topic.title.find(searchString) != -1:
            indexes.append(index + 1)
    print "Found: " + str(indexes)
Exemplo n.º 12
0
    def post(self):
        json_obj = json_decode(self.request.body)
        #print 'Post data received'
        #for key in list(json_obj.keys()):
        #   print 'key: %s , value: %s' % (key, json_obj[key])
        print json_obj['key1']

        # new dictionary
        response_to_send = {}
        #response_to_send['newkey'] = json_obj['key1']
        #response_to_send['topic'] = tp.topicFreqDB(tp.statisticSchoolTopic(board, json_obj['key1']))
        #print('Response to return')
        #pprint.pprint(response_to_send)
        response_to_send['topic'] = tp.placeTopic(board, json_obj['key1'])
        self.write(json.dumps(response_to_send))
Exemplo n.º 13
0
def editCommand(command):
    #print "Editing command " + constants.OKBLUE + command + constants.RESET
    commandParts = command.split(' ')
    index = int(commandParts[0]) - 1
    value = commandParts[2]
    option = commandParts[1]
    # Get topic
    jsonData = loadFile()
    mangager = Topic.TopicsManger()
    topics = mangager.fromJson(jsonData)
    topic = topics[index]
    # Action from command
    if option == "ct":
        topic.title = value
        print "Changind title to " + value
    elif option == "al":
        topic.links.append(value)
        print "Adding link " + value
    elif option == "cc":
        topic.comment = value
        print "Changing comment to " + value
    #Save new data
    jsonData = mangager.toJson()
    saveFile(jsonData)
Exemplo n.º 14
0
user = User()
u = user.login('18052098217', 'Www.google.com2')

# 一个获取问题所有回答相关信息的例子
# Question('24183980',u).archieve_answerlist('')

# 一个获取回答基本信息的例子,
# 还可以获取所有收藏该回答的收藏夹以及所有点赞用户
# ans = Answer('https://www.zhihu.com/question/54446315/answer/159712952',u)
# ans.archieve_answer_list('voters')

# 一个获取用户基本信息的例子
# user.archieve_userinfo('shotgun')

# 一个用来获取用户所有粉丝和关注列表的例子关注的专栏和所有的提问等信息
'''
	followers,followees,following-columns,following-questions,asks
'''
# user.archieve_list('sgai','followers')

# 一个用来获取话题所有精华问题的例子
'''
话题精华问题:top-answers 所有问题:questions
'''
t = Topic('19610067', u)
t.archieve_list(10, 'questions')
# t.save_list('Test.xls')

# 一个用来获取专栏所有文章的例子
# Column('shitumao',u).archieve_articles()
Exemplo n.º 15
0
    def initiate_clustering(self):

        while (True):
            try:
                number_of_clusters = raw_input("Enter number of clusters: ")
                number_of_clusters = int(number_of_clusters)
                if number_of_clusters > len(self.jobs_fetched):
                    print 'Number of clusters cannot be greater than total number of jobs fetched.'
                else:
                    break
            except:
                print "Invalid input. Please try again."

        job_documents = []

        for job in self.jobs_fetched:
            desc = " ".join(job.summary)
            job_documents.append(desc)

        # for doc in job_documents:
        #     print doc+"\n\n"

        kmeans = KmeansClusteringAgent(self.jobs_fetched)
        clusters, closest = kmeans.start(job_documents, number_of_clusters)

        clusters_obj_list = []
        for index, cluster in clusters.items():
            cl = Cluster()
            cl.cluster_id = index
            cl.cluster = cluster
            cl.closest_job_document = self.jobs_fetched[closest[index]]

            print "\nCluster" + str(
                cl.cluster_id) + "--------------------------"
            for job in cl.cluster:
                print "\t" + job.jobTitle.encode('ascii', 'ignore')
            print "\n Job closest to centroid in cluster " + str(
                cl.cluster_id) + ": \n"
            cl.closest_job_document.printDetails()
            clusters_obj_list.append(cl)

        while (True):
            try:
                number_of_clusters_for_nlp = raw_input(
                    "\n\nEnter number of course topics to generate: ")
                number_of_clusters_for_nlp = int(number_of_clusters_for_nlp)
                if (number_of_clusters_for_nlp > number_of_clusters):
                    print 'Enter a number less than the number of clusters.'
                else:
                    break
            except:
                print "Invalid input. Please try again."

        print 'Below are ' + str(
            number_of_clusters_for_nlp
        ) + ' clusters built using Kmeans in descending order of size of cluster'
        final_clusters_for_nlp = []
        topics = []
        count = 0
        for k in sorted(clusters, key=lambda k: len(clusters[k]),
                        reverse=True):
            count += 1
            print "\nCluster" + str(k) + "---------------"

            for cluster_obj in clusters_obj_list:
                if cluster_obj.cluster_id == k:
                    final_clusters_for_nlp.append(cluster_obj)

                    print 'Initiating single-link hierarchical clustering on Cluster ' + str(
                        k)
                    single_link_clustering_agent = SingleLinkClusteringAgent()
                    single_link_clustering_agent.cluster = cluster_obj
                    parent_job = single_link_clustering_agent.start()

                    cluster_obj.parent_job_from_single_link = parent_job

                    print 'Parent job from hierarchy:'
                    cluster_obj.parent_job_from_single_link.printDetails()

                    print 'Fetching course topic and contents..'
                    topic = Topic()
                    topic.cluster = cluster_obj
                    topic.set_syllabus_content()
                    topics.append(topic)

                    print 'Topic fetched..'
                    break

            if count == number_of_clusters_for_nlp:
                break

        print '\n\nRecommended Topics----------------------------'
        for topic in topics:

            print(
                "\nTopic: -----------------------------------------------------------------------------------"
            )
            print("Topics in " + topic.topic + "\n")
            print(
                "Course Description: ----------------------------------------------------------------------"
            )
            print("Introduction to topics in " + topic.topic + " such as " +
                  str(topic.technologies) + str(topic.listedTech))

            print(
                "\nCourse Learning Outcomes: -----------------------------------------------------------------"
            )
            print topic.actionList
            print('Summary:')
            print(topic.summary.encode('ascii', 'ignore'))
            print("\n")

            self.utils.generate_pdf(topic)
import sys
sys.path.append('./')

import Topic
import Link
import Searching

manager = Topic.TopicsManger()
topic = Topic.Topic()
topic.title = "abracadabra"
link = Link.Link()
link.url = "link_ura"
link.tags.append("arad")
link.tags.append("iasi")
topic.links.append(link)
manager.add(topic)


def test1():
    queries = [('arg0', 'abra')]
    result = Searching.generalSearch(queries, manager)

    if result[0][0].title == "abracadabra":
        print "Test1 OK"
    else:
        print "Test1 Failed"


def test2():
    queries = [('arg0', 'ura')]
    result = Searching.generalSearch(queries, manager)
Exemplo n.º 17
0
async def on_message(message):
    if message.author == client.user:
        return

    eye = "\U0001F441"

    if message.content.startswith(eye) == False:
        return

    explode = message.content.split(' ', 2)

    if explode[0] == "\U0001F441status":
        await client.send_typing(message.channel)
        try:
            topic = Topic.Topic()
            response = parse_qs(topic.send_topic("status"))

            outmsg = "**Version:** " + response["version"][0] + "\n"
            outmsg += "**Gamemode:** " + response["mode"][0] + "\n"
            states = [
                "Starting Up", "Lobby", "Setting Up", "In Progress", "Finished"
            ]
            outmsg += "**State:** " + states[int(
                response["gamestate"][0])] + "\n"
            outmsg += "**Players:** " + response["admins"][0] + "\n"
            outmsg += "**Admins:** " + response["active_players"][0] + "\n"

            roundseconds = int(response["round_duration"][0])
            roundhours = 12 + int(math.floor(roundseconds / 3600))
            roundseconds %= 3600
            roundminutes = int(math.floor(roundseconds / 60))
            roundseconds %= 60
            outmsg += "**Time:** {h:02d}:{m:02d}:{s:02d}".format(
                h=roundhours, m=roundminutes, s=roundseconds)
        except ConnectionError as e:
            outmsg = "Server appears to be down!"

        await client.send_message(message.channel, outmsg)

    if explode[0] == "\U0001F441bwoink":
        await client.send_typing(message.channel)
        try:
            topic = Topic.Topic()
            outmsg = topic.send_topic("adminmsg=" + explode[1] + "&msg=" +
                                      explode[2] + "&sender=" +
                                      message.author.name)
        except ConnectionError as e:
            outmsg = "Server appears to be down!"

        await client.send_message(message.channel, outmsg)

    if explode[0] == "\U0001F441notes" and message.server.id == cfg['discord'][
            'staffserverID']:  # Check it's in the correct server
        output = ""
        ckey = ""
        if len(explode) > 1:
            ckey = explode[1]
        else:
            output = "No argument specified."
            await client.send_message(message.channel, output)
            return

        db = pymysql.connect(cfg["mysql"]["host"], cfg["mysql"]["user"],
                             cfg["mysql"]["passwd"], cfg["mysql"]["db"])
        try:
            with db.cursor() as cursor:
                query = "SELECT `notetext`, `timestamp`, `adminckey`, `last_editor` FROM notes WHERE ckey LIKE \'" + ckey + "\'"
                cursor.execute(query)
                result = cursor.fetchall()
                if result:
                    output = "Notes for player " + ckey + "\n\n"
                    for line in result:
                        output += "``` " + line[0] + "\n"
                        output += "added at " + str(
                            line[1]) + " by " + line[2] + "\n\n"
                        output += "```"
                else:
                    output = "No results found for " + ckey

        finally:
            await client.send_message(message.channel, output)
            del (cursor)
            db.close()
Exemplo n.º 18
0
async def on_message(message):
    if message.author == client.user:
        return

    eye = "\U0001F441"

    if message.content.startswith(eye) == False:
        return

    explode = message.content.split(' ')

    if explode[0] == "\U0001F441status":
        await client.send_typing(message.channel)
        try:
            topic = Topic.Topic()
            response = parse_qs(topic.send_topic("status"))

            outmsg = "**Gamemode:** " + response["mode"][0] + "\n"
            states = [
                "Starting Up", "Lobby", "Setting Up", "In Progress", "Finished"
            ]
            outmsg += "**State:** " + states[int(
                response["gamestate"][0])] + "\n"
            outmsg += "**Admins:** " + response["admins"][0] + "\n"
            outmsg += "**Players:** " + response["active_players"][0] + "\n"

            roundseconds = int(response["round_duration"][0])
            roundhours = 12 + int(math.floor(roundseconds / 3600))
            roundseconds %= 3600
            roundminutes = int(math.floor(roundseconds / 60))
            roundseconds %= 60
            outmsg += "**Time:** {h:02d}:{m:02d}:{s:02d}".format(
                h=roundhours, m=roundminutes, s=roundseconds)
        except ConnectionError as e:
            outmsg = "Server appears to be down!"

        await client.send_message(message.channel, outmsg)

    if explode[0] == "\U0001F441bwoink" and message.server.id == cfg[
            'discord']['staffserverID']:
        await client.send_typing(message.channel)
        try:
            topic = Topic.Topic()
            outmsg = topic.send_topic("adminmsg=" + explode[1] + "&msg=" +
                                      explode[2] + "&sender=" +
                                      message.author.name)
        except ConnectionError as e:
            outmsg = "Server appears to be down!"

        await client.send_message(message.channel, outmsg)

    if explode[0] == "\U0001F441notes" and await staffServerCheck(
            message.server.id):  # Check it's in the correct server
        output = ""
        ckey = ""
        if len(explode) == 2:
            ckey = explode[1]
        elif len(explode) > 2:
            ckey = " ".join(explode[1:])
        else:
            output = "No argument specified."
            await client.send_message(message.channel, output)
            return

        query = "SELECT `text`, `timestamp`, `adminckey`, `lasteditor` FROM messages WHERE targetckey LIKE \'{0}\'".format(
            ckey)
        result = await queryMySql(query)
        if result:
            output = "Notes for player " + ckey + "\n\n"
            for line in result:
                newnote = "```" + line[0] + "\n"
                newnote += "added at " + str(
                    line[1]) + " by " + line[2] + "\n\n"
                newnote += "```"

                if len(output + newnote) > 2000:
                    """If the message would be over 2000 characters then output the message and then reset"""
                    await client.send_message(message.channel, output)
                    output = newnote
                else:
                    output = output + newnote

        else:
            output = "No results found for " + ckey

        await client.send_message(message.channel, output)

    if explode[0] == "\U0001F441info" and await staffServerCheck(
            message.server.id):
        output = ""
        ckey = ""
        if len(explode) == 2:
            ckey = explode[1]
        elif len(explode) > 2:
            ckey = " ".join(explode[1:])
        else:
            output = "No argument specified."
            await client.send_message(message.channel, output)
            return

        query = "SELECT `accountjoindate`, `firstseen`, `lastseen`, `computerid`, `ip` FROM player WHERE ckey LIKE \'{0}\';".format(
            ckey)
        result = await queryMySql(query)

        if result:
            output = "Player information for **{0}**:\n\n".format(ckey)
            for line in result:
                output += "```Join Date: {0}\nFirst Seen: {1}\nLast Seen: {2}\nComputer ID: {3}\nIP: {4}```".format(
                    line[0], line[1], line[2], line[3], line[4])
                return await client.send_message(message.channel, output)
        else:
            return await client.send_message(
                message.channel, "No result found for {0}".format(ckey))

    if explode[0] == "\U0001F441searchban" and await staffServerCheck(
            message.server.id):
        output = ""
        ckey = ""
        if len(explode) == 2:
            ckey = explode[1]
        elif len(explode) > 2:
            ckey = " ".join(explode[1:])
        else:
            output = "No argument specified."
            return await client.send_message(message.channel, output)

        query = "SELECT `bantype`, `bantime`, `expiration_time`, `computerid`, `ip`, `adminwho`,`unbanned`,`unbanned_datetime`, `duration`, `reason` FROM ban WHERE ckey LIKE \'{0}\';".format(
            ckey)
        result = await queryMySql(query)
        if result:
            output = "Ban information for **{0}**:\n\n".format(ckey)
            for line in result:
                if len(output) > 1500:
                    await client.send_message(message.channel, output)
                    output = ""
                output += "```Ban Type: {0} duration {1} minutes placed by {2} on {3}.\n".format(
                    line[0], line[8], line[5], line[1])
                output += "Expiry Time: {0}\n".format(line[2])
                output += "Reason: {0}\n".format(line[9])
                output += "Unbanned: {0} {1}\n```".format(
                    "YES at" if str(line[6]) == "1" else "NO",
                    line[7] if str(line[6]) == "1" else "")
            return await client.send_message(message.channel, output)
Exemplo n.º 19
0
    def setup_skills_and_interests(self):
        self.skills = []
        self.empty_skills = []
        self.topics = []
        self.empty_topics = []
        cursor = self.conn.cursor()
        # Get the user's interests
        qry = "select * from topic_interests TI, topics T, courses C where \
                            TI.username = ? and TI.topic_id = T.topic_id and \
                            C.course_id = TI.course_id"
        query_out = cursor.execute(qry, (self.username,))
        topic_tups = query_out.fetchall()
        for topic_tup in topic_tups:
            self.add_complete_topic(Topic(topic_tup))

        # Get the user's skills
        qry = "select * from skill_rankings SR, skills S, courses C where \
                            SR.username = ? and SR.skill_id = S.skill_id and \
                            C.course_id = SR.course_id"
        query_out = cursor.execute(qry,(self.username,))
        skill_tups = query_out.fetchall()
        for skill_tup in skill_tups:
            self.add_complete_skill(Skill(skill_tup))

        # Get unranked skills
        # Get all skills the user could have and subtract the ones they don't
        select = "select distinct CS.skill_id, CS.course_id, E.edition_id, \
                                        C.dept_code, C.course_number, S.skill"
        tables = "from course_skills CS, enrollments E, course_editions CE, \
                                        courses C , skills S"

        inner_qry = "(select distinct SR.skill_id from \
                                skill_rankings SR where SR.username = ?)"
        where = "where E.username = ? and E.edition_id = CE.edition_id and \
            CE.course_id = CS.course_id and C.course_id = CS.course_id and \
            S.skill_id = CS.skill_id and CS.skill_id not in " + inner_qry
        grouping = "group by CS.skill_id"
        qry = " ".join([select, tables, where, grouping])
        query_out = cursor.execute(qry,(self.username, self.username,))
        skill_tups = query_out.fetchall()
        for sid, cid, eid, dept, cnum, sname in skill_tups:
            self.add_empty_skill(Skill((cid, eid, None, sid, None, None, None, \
                                                sname, None, dept, cnum, None)))


        # Get unranked interests:
        select = "select distinct CT.topic_id, CT.course_id, E.edition_id, \
                                    C.dept_code, C.course_number, T.topic"
        tables = "from course_topics CT, enrollments E, course_editions CE, \
                                                    courses C , topics T"
        inner_qry = "(select distinct TI.topic_id from topic_interests TI \
                                                    where TI.username = ?)"
        where = "where E.username = ? and E.edition_id = CE.edition_id and \
                CE.course_id = CT.course_id and C.course_id = CT.course_id and \
                T.topic_id = CT.topic_id and CT.topic_id not in " + inner_qry
        grouping = "group by CT.topic_id"
        qry = " ".join([select, tables, where, grouping])
        query_out = cursor.execute(qry,(self.username, self.username))
        topic_tups = query_out.fetchall()
        for tid, cid, eid, dept, cnum, tname in topic_tups:
            self.add_empty_topic(Topic((cid, eid, None, tid, None, None, None, \
                            tname, None, dept, cnum, None)))
Exemplo n.º 20
0
def createTopics(category):
    topicList = getTopicList(category)
    for topic in topicList:
        newTopic = Topic(topic, category)
        newTopic.save()