Last active
March 3, 2022 02:22
-
-
Save hi-upchen/6ccf4e06c2a9cf452202da2679dbc84d to your computer and use it in GitHub Desktop.
This script grabs the articles from P8 and save the articles data into data extension (tw-p8-rss-article-matrix)
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
%%[ | |
SET @xml = HTTPGet("https://www.greenpeace.org/taiwan/feed") | |
SET @xml = Replace(@xml,'media:thumbnail','mediathumbnail') | |
SET @nodes = BuildRowsetFromXML(@xml,"//item",0) | |
SET @rowCount = RowCount(@nodes) | |
IF @rowCount > 0 THEN | |
FOR @i = 1 TO @rowCount DO | |
VAR @title, @desc, @link, @pubDate, @thumbnail | |
SET @titleRows = BuildRowsetFromXML(@xml,'//item/title',0) | |
IF RowCount(@titleRows) > 0 THEN | |
SET @title = Field(Row(@titleRows,@i),"Value") /* OUTPUTLINE(CONCAT("title:", @title,"<br /> ")) */ | |
ENDIF | |
SET @descRows = BuildRowsetFromXML(@xml,'//item/description',0) | |
IF RowCount(@descRows) > 0 THEN | |
SET @desc = Field(Row(@descRows,@i),"Value") /* OUTPUTLINE(CONCAT("desc:", @desc,"<br /> ")) */ | |
ENDIF | |
SET @linkRows = BuildRowsetFromXML(@xml,"//item/link",0) | |
IF RowCount(@linkRows) > 0 THEN | |
SET @link = Field(Row(@linkRows,@i),"Value") /* OUTPUTLINE(CONCAT("link:", @link,"<br /> ")) */ | |
ENDIF | |
SET @pubDateRows = BuildRowsetFromXML(@xml,"//item/pubDate",0) | |
IF RowCount(@pubDateRows) > 0 THEN | |
SET @pubDate = Field(Row(@pubDateRows,@i),"Value") | |
SET @month = FormatDate(@pubDate,"MM") | |
SET @day = FormatDate(@pubDate,"dd") | |
SET @year = FormatDate(@pubDate,"YYYY") | |
SET @fullDate = Concat(@month,"/",@day,"/",@year) /* OUTPUTLINE(CONCAT("pubDate:", @pubDate,"<br /> ")) */ | |
ENDIF | |
SET @thumbnailRows = BuildRowsetFromXML(@xml,"//item/mediathumbnail",0) | |
IF RowCount(@thumbnailRows) > 0 THEN | |
SET @thumbnail = Field(Row(@thumbnailRows,@i),"Url_att") /* OUTPUTLINE(CONCAT("thumbnail:", "<img src="",@thumbnail,"" style="width:200px;'" />","<br /> ")) */ | |
ENDIF | |
SET @nodepath = concat("//item[",@i,"]/") | |
SET @categoryRows = RowCount(BuildRowsetFromXML(@xml,ConCat(@nodepath,"category"))) VAR @categoryArr | |
IF @categoryRows > 0 THEN | |
FOR @c = 1 TO @categoryRows DO | |
SET @category = Field(Row(BuildRowsetFromXML(@xml,ConCat(@nodepath,"category"),0),@c),'Value') | |
SET @categoryArr = CONCAT(@category,", ", @categoryArr) | |
NEXT @c /* OUTPUTLINE(CONCAT("Categories: ", @categoryArr,"<br /> ")) */ | |
ENDIF /* OUTPUTLINE(CONCAT("item node", @i,"<br /> ")) */ | |
SET @categoryArr = SUBSTRING(@categoryArr, 1, SUBTRACT(LENGTH(@categoryArr), 2)) OUTPUTLINE(CONCAT("Categories: ", @categoryArr,"<br /> ")) | |
SET @Upsert = UpsertData("tw-p8-rss-article-matrix", 1, "link",@link, "title", @title, "desc", @desc, "thumbnail",@thumbnail, "pubDate",@fullDate, "category",@categoryArr, "isSendable","true" ) | |
NEXT @i | |
ENDIF ]%% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment