使用Wikipedia API和Python 2.7从列表中提取特定用户注释(Extract specific users comments from a list using Wikipedia API and Python 2.7)
我正在使用维基百科API - wikitools包从维基百科中提取一些数据。 我得到下面显示的格式的输出,现在我想提取几个页面的特定用户的修订的时间戳和注释。 假设我只想要TechBot发表的评论,然后我想我可以做类似的事情:
for revision in res["query"]["pages"]["7940378"]["revisions"]: if revision["user"] = "Techbot": do.something()
但问题是[“7940378”],因为这是一个唯一的页面ID,并将为每个页面更改,我不知道如何获取pageid。 还有另一种方法吗?
[{ "query": { "pages": { "7940378": { "ns": 0, "pageid": 7940378, "revisions": [ { "comment": "robot Modifying: [[az:T\u00fcrk Tarixi]]", "timestamp": "2009-01-03T19:47:11Z", "user": "TechBot" }, { "comment": "", "timestamp": "2009-02-14T02:07:49Z", "anon": "", "user": "88.231.237.130" }, { "comment": "fixing recent deletion by merging it with the next paragraph", "timestamp": "2009-04-03T14:49:27Z", "user": "Soap" }, { "comment": "robot Modifying: [[az:T\u00fcrk tarixi]]", "timestamp": "2009-04-09T14:35:19Z", "user": "RibotBOT" }, { "comment": "Repairing link to disambiguation page - [[Wikipedia:Disambiguation pages with links|You can help!]]", "timestamp": "2009-06-12T23:55:55Z", "user": "J04n" } ], "title": "History of the Turkic peoples" } } }, "continue": { "rvcontinue": "20090807172715|306635892", "continue": "||" }, "warnings": { "main": { "*": "Unrecognized parameter: 'user'" } } }]
I am using the wikipedia API - wikitools package to extract some data from Wikipedia. I get the output of the format shown below and now I want to extract the timestamp and the comment for revisions made of specific user for several pages. Let's say I just want the comments made by TechBot, then I figured that I can do something like:
for revision in res["query"]["pages"]["7940378"]["revisions"]: if revision["user"] = "Techbot": do.something()
But the problem is ["7940378"] because this is a unique page id and will change for every page and I dont know how to get the pageid. Is there another way of doing this?
[{ "query": { "pages": { "7940378": { "ns": 0, "pageid": 7940378, "revisions": [ { "comment": "robot Modifying: [[az:T\u00fcrk Tarixi]]", "timestamp": "2009-01-03T19:47:11Z", "user": "TechBot" }, { "comment": "", "timestamp": "2009-02-14T02:07:49Z", "anon": "", "user": "88.231.237.130" }, { "comment": "fixing recent deletion by merging it with the next paragraph", "timestamp": "2009-04-03T14:49:27Z", "user": "Soap" }, { "comment": "robot Modifying: [[az:T\u00fcrk tarixi]]", "timestamp": "2009-04-09T14:35:19Z", "user": "RibotBOT" }, { "comment": "Repairing link to disambiguation page - [[Wikipedia:Disambiguation pages with links|You can help!]]", "timestamp": "2009-06-12T23:55:55Z", "user": "J04n" } ], "title": "History of the Turkic peoples" } } }, "continue": { "rvcontinue": "20090807172715|306635892", "continue": "||" }, "warnings": { "main": { "*": "Unrecognized parameter: 'user'" } } }]
原文:https://stackoverflow.com/questions/36422266
最满意答案
以下查询将帮助你:)
INSERT INTO SubHeadings (SubHeadingName, HeadingID) SELECT subhdng.SubHeadingName, hdng.HeadingID FROM Headings hdng INNER JOIN SubHeadings subhdng ON hdng.HeadingID = subhdng.HeadingID WHERE hdng.TopicID = 2
Following query will help you :)
INSERT INTO SubHeadings (SubHeadingName, HeadingID) SELECT subhdng.SubHeadingName, hdng.HeadingID FROM Headings hdng INNER JOIN SubHeadings subhdng ON hdng.HeadingID = subhdng.HeadingID WHERE hdng.TopicID = 2
相关问答
更多-
暂时禁用更新PK和FK数据类型的限制(Temporarily deactivate constraints for updating datatype of PKs and FKs)[2022-03-21]
我找到了一种创建所有查询的方法来删除和创建数据库的所有约束。 所以首先我必须保存第一个查询的输出 SELECT 'ALTER TABLE "'||nspname||'"."'||relname||'" DROP CONSTRAINT "'||conname||'";' FROM pg_constraint INNER JOIN pg_class ON conrelid=pg_class.oid INNER JOIN pg_namespace ON pg_namespace.oid=pg_class ... -
以下查询将帮助你:) INSERT INTO SubHeadings (SubHeadingName, HeadingID) SELECT subhdng.SubHeadingName, hdng.HeadingID FROM Headings hdng INNER JOIN SubHeadings subhdng ON hdng.HeadingID = subhdng.HeadingID WHERE hdng.TopicID = 2 Following query will help you :) ...
-
根据您的要求,您可以: 编写存储过程以执行插入并配置NHibernate以在映射中使用此过程。 在处理遗留数据库和未使用但必须填充的历史字段时,我采用了这种方法 使用拦截器 。 以下内容应该有效。 虽然没经过测试! public class TransactionEntityInterceptor : EmptyInterceptor { public override boolean OnSave(object entity, object id, ...
-
Hibernate何时创建从FK到非PK列的新条目?(When does Hibernate create a new entry from a FK to a non-PK column?)[2023-11-25]
这是级联anotation,如果你不想在db中创建表2,不要将它设置为子,但如果你想要更新表2,你需要表2 id。 或者,您可以在表1的hbm中设置cascade =“none”或cascade =“update”,但是如果没有id,表2仍然不会更新。 It's the cascade anotation, if you dont want table 2 to be created in the db, dont set it as a child, but if you want table 2 to ... -
如果我正确理解你的问题,你样品表格图像的预期结果将是1,4。 像这样的东西应该让你开始。 DECLARE @Test TABLE ( PropertyId INT PRIMARY KEY, CustomerId INT ); INSERT @Test ( PropertyId, CustomerId ) VALUES ( 1, 1 ), ( 2, 2 ), (3, 3 ), ( 4, 1 ); SELECT PropertyId FROM @Test WHERE ...
-
答案是因为Hast说我没有在我的文章表中的FK item_id中定义'CASCADE ON DELETE'。 The answer was as Hast said that I didn't defined 'CASCADE ON DELETE' at my FK item_id in my article table.
-
PK,FK约束设计(PK, FK Constraints design)[2022-03-30]
员工应该是SALARY_DETAILS和INCOME_TAX都引用的单独表。 这样,您可以消除冗余并修复您的FK问题。 EMPLOYEES should be a separate table that both SALARY_DETAILS and INCOME_TAX refer to. This way, you can eliminate redundancy and also fix your FK problems. -
添加JoinColumn批注 @JoinColumn(name = "id_manufacturor", referencedColumnName = "id") Name是数据库中的FK列名(不是实体)。 referencedColumnName“id”必须与manufacturer表中定义的id相对应。 Add the JoinColumn Annotation @JoinColumn(name = "id_manufacturor", referencedColumnName = "id") Na ...
-
使用fluent API映射关系。 protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity
() .HasRequired(p => p.Owner) .WithOptional(); } 更新: 一对一关系只能使用称为“共享主键”的映射技术建模。 也就是说,依赖实体的PK也是FK。 从属实体(即Profile )中没 ... -
尝试这样更改您的Review实体 Review: ... manyToMany: topics: targetEntity: Topic joinTable: name: reviews_topics joinColumns: review_id: referencedColumnName: idReview inverseJoinColumns: ...