Compare commits
2 Commits
d7fdb48b4a
...
92240b9819
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92240b9819 | ||
|
|
9b5a98fa01 |
230
app/src/main/kotlin/rasel/lunar/launcher/model/CommunityData.kt
Normal file
230
app/src/main/kotlin/rasel/lunar/launcher/model/CommunityData.kt
Normal file
@ -0,0 +1,230 @@
|
|||||||
|
package rasel.lunar.launcher.model
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.work.Worker
|
||||||
|
import androidx.work.WorkerParameters
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.jsoup.Jsoup
|
||||||
|
import org.jsoup.nodes.Document
|
||||||
|
import rasel.lunar.launcher.home.LauncherHome.Companion.rssSet
|
||||||
|
import rasel.lunar.launcher.todos.Root
|
||||||
|
import rasel.lunar.launcher.todos.RssDataItem
|
||||||
|
import rasel.lunar.launcher.todos.RssDataType
|
||||||
|
import rasel.lunar.launcher.todos.RssFeedsParser
|
||||||
|
import rasel.lunar.launcher.utils.BLog
|
||||||
|
import rasel.lunar.launcher.utils.RssList
|
||||||
|
import rasel.lunar.launcher.utils.RssList.feedJsons
|
||||||
|
import rasel.lunar.launcher.utils.beforeDay
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
|
||||||
|
class DCGetter : Worker {
|
||||||
|
companion object {
|
||||||
|
val TAG = "DCGetter"
|
||||||
|
}
|
||||||
|
constructor(context: Context, workerParams: WorkerParameters) : super(context, workerParams) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun parseDcLi(dc_li : org.jsoup.nodes.Element) : ArrayList<RssDataItem>{
|
||||||
|
var temp = arrayListOf<RssDataItem>()
|
||||||
|
if (dc_li.html().contains("<ul class=>") && dc_li.html().contains("con_list img")) {
|
||||||
|
dc_li.child(0).getElementsByTag("li").forEach {
|
||||||
|
parseDcLi(it)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var link = if (dc_li.getElementsByTag("a").size > 0) dc_li.getElementsByTag("a").get(0)
|
||||||
|
.attr("href") else ""
|
||||||
|
var title =
|
||||||
|
if (dc_li.getElementsByClass("box besttxt").size > 0) dc_li.getElementsByClass("box besttxt")
|
||||||
|
.get(0)
|
||||||
|
.text() else if (dc_li.getElementsByClass("tit").size > 0) dc_li.getElementsByClass(
|
||||||
|
"tit"
|
||||||
|
).get(0).text() else ""
|
||||||
|
var thumbnail =
|
||||||
|
if (dc_li.getElementsByTag("img").size > 0) dc_li.getElementsByTag("img").get(0)
|
||||||
|
.attr("src") else ""
|
||||||
|
var desc =
|
||||||
|
if (dc_li.getElementsByClass("box best_info").size > 0) dc_li.getElementsByClass("box best_info")
|
||||||
|
.get(0).text() else ""
|
||||||
|
var dateTiem =
|
||||||
|
if (dc_li.getElementsByClass("time").size > 0) dc_li.getElementsByClass("time")
|
||||||
|
.get(0).text() else ""
|
||||||
|
link = link.replace("&","&")
|
||||||
|
thumbnail = thumbnail.replace("&","&")
|
||||||
|
BLog.LOGE("DC_LI >>>> link >>>> ${link}")
|
||||||
|
BLog.LOGE("DC_LI >>>> title >>>> ${title}")
|
||||||
|
BLog.LOGE("DC_LI >>>> thumbnail >>>> ${thumbnail}")
|
||||||
|
BLog.LOGE("DC_LI >>>> desc >>>> ${desc}")
|
||||||
|
BLog.LOGE("DC_LI >>>> dateTiem >>>> ${dateTiem}")
|
||||||
|
if (title.length > 0 && link.length > 0) {
|
||||||
|
DcInside().apply {
|
||||||
|
this.link = link
|
||||||
|
this.title = title
|
||||||
|
this.thumbnail = thumbnail
|
||||||
|
this.desc = desc
|
||||||
|
this.dateTiem = dateTiem
|
||||||
|
}.apply {
|
||||||
|
temp.add(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return temp
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("RestrictedApi")
|
||||||
|
override fun doWork(): Result {
|
||||||
|
|
||||||
|
var tempArray = arrayListOf<RssDataItem>()
|
||||||
|
|
||||||
|
try {
|
||||||
|
val testUrl2 = "https://www.dcinside.com/"
|
||||||
|
Jsoup.connect(testUrl2).userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15").get().let { dc ->
|
||||||
|
// BLog.LOGE("test ${testUrl2} >> ${this}")
|
||||||
|
dc.getElementsByTag("li").forEach { dc_li ->
|
||||||
|
if (dc_li.html().contains("main_log") == true) {
|
||||||
|
parseDcLi(dc_li).apply {
|
||||||
|
tempArray.addAll(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e:Exception){e.printStackTrace()}
|
||||||
|
return tempArray.forEach {
|
||||||
|
rssSet.put(it.originPage(),it)
|
||||||
|
}.run {
|
||||||
|
Result.success()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fun parseDcLi(dc_li : org.jsoup.nodes.Element) : ArrayList<RssDataItem>{
|
||||||
|
var temp = arrayListOf<RssDataItem>()
|
||||||
|
if (dc_li.html().contains("<ul class=>") && dc_li.html().contains("con_list img")) {
|
||||||
|
dc_li.child(0).getElementsByTag("li").forEach {
|
||||||
|
parseDcLi(it)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var link = if (dc_li.getElementsByTag("a").size > 0) dc_li.getElementsByTag("a").get(0)
|
||||||
|
.attr("href") else ""
|
||||||
|
var title =
|
||||||
|
if (dc_li.getElementsByClass("box besttxt").size > 0) dc_li.getElementsByClass("box besttxt")
|
||||||
|
.get(0)
|
||||||
|
.text() else if (dc_li.getElementsByClass("tit").size > 0) dc_li.getElementsByClass(
|
||||||
|
"tit"
|
||||||
|
).get(0).text() else ""
|
||||||
|
var thumbnail =
|
||||||
|
if (dc_li.getElementsByTag("img").size > 0) dc_li.getElementsByTag("img").get(0)
|
||||||
|
.attr("src") else ""
|
||||||
|
var desc =
|
||||||
|
if (dc_li.getElementsByClass("box best_info").size > 0) dc_li.getElementsByClass("box best_info")
|
||||||
|
.get(0).text() else ""
|
||||||
|
var dateTiem =
|
||||||
|
if (dc_li.getElementsByClass("time").size > 0) dc_li.getElementsByClass("time")
|
||||||
|
.get(0).text() else ""
|
||||||
|
link = link.replace("&","&")
|
||||||
|
thumbnail = thumbnail.replace("&","&")
|
||||||
|
BLog.LOGE("DC_LI >>>> link >>>> ${link}")
|
||||||
|
BLog.LOGE("DC_LI >>>> title >>>> ${title}")
|
||||||
|
BLog.LOGE("DC_LI >>>> thumbnail >>>> ${thumbnail}")
|
||||||
|
BLog.LOGE("DC_LI >>>> desc >>>> ${desc}")
|
||||||
|
BLog.LOGE("DC_LI >>>> dateTiem >>>> ${dateTiem}")
|
||||||
|
if (title.length > 0 && link.length > 0) {
|
||||||
|
DcInside().apply {
|
||||||
|
this.link = link
|
||||||
|
this.title = title
|
||||||
|
this.thumbnail = thumbnail
|
||||||
|
this.desc = desc
|
||||||
|
this.dateTiem = dateTiem
|
||||||
|
}.apply {
|
||||||
|
temp.add(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return temp
|
||||||
|
}
|
||||||
|
|
||||||
|
class DcInside : RssDataItem {
|
||||||
|
var link : String? = null
|
||||||
|
var title : String? = null
|
||||||
|
var thumbnail : String? = null
|
||||||
|
var desc : String? = null
|
||||||
|
var dateTiem : String? = null
|
||||||
|
|
||||||
|
val dateF = SimpleDateFormat("MM:dd")
|
||||||
|
val timeF = SimpleDateFormat("hh:mm")
|
||||||
|
override fun title(): String {
|
||||||
|
return title ?:""
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun thumbnailUrl(): String {
|
||||||
|
return thumbnail ?:""
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun originPage(): String {
|
||||||
|
return link ?:""
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun description(): String {
|
||||||
|
return desc ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pubDate(): Long {
|
||||||
|
return if(dateTiem?.contains(":") == true) timeF.parse(dateTiem).time else dateF.parse(dateTiem).time
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun category(): RssDataType {
|
||||||
|
return RssDataType.NewsFeed
|
||||||
|
}
|
||||||
|
|
||||||
|
fun parseDcLi(dc_li : org.jsoup.nodes.Element) : ArrayList<RssDataItem>{
|
||||||
|
var temp = arrayListOf<RssDataItem>()
|
||||||
|
if (dc_li.html().contains("<ul class=>") && dc_li.html().contains("con_list img")) {
|
||||||
|
dc_li.child(0).getElementsByTag("li").forEach {
|
||||||
|
parseDcLi(it)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var link = if (dc_li.getElementsByTag("a").size > 0) dc_li.getElementsByTag("a").get(0)
|
||||||
|
.attr("href") else ""
|
||||||
|
var title =
|
||||||
|
if (dc_li.getElementsByClass("box besttxt").size > 0) dc_li.getElementsByClass("box besttxt")
|
||||||
|
.get(0)
|
||||||
|
.text() else if (dc_li.getElementsByClass("tit").size > 0) dc_li.getElementsByClass(
|
||||||
|
"tit"
|
||||||
|
).get(0).text() else ""
|
||||||
|
var thumbnail =
|
||||||
|
if (dc_li.getElementsByTag("img").size > 0) dc_li.getElementsByTag("img").get(0)
|
||||||
|
.attr("src") else ""
|
||||||
|
var desc =
|
||||||
|
if (dc_li.getElementsByClass("box best_info").size > 0) dc_li.getElementsByClass("box best_info")
|
||||||
|
.get(0).text() else ""
|
||||||
|
var dateTiem =
|
||||||
|
if (dc_li.getElementsByClass("time").size > 0) dc_li.getElementsByClass("time")
|
||||||
|
.get(0).text() else ""
|
||||||
|
link = link.replace("&","&")
|
||||||
|
thumbnail = thumbnail.replace("&","&")
|
||||||
|
BLog.LOGE("DC_LI >>>> link >>>> ${link}")
|
||||||
|
BLog.LOGE("DC_LI >>>> title >>>> ${title}")
|
||||||
|
BLog.LOGE("DC_LI >>>> thumbnail >>>> ${thumbnail}")
|
||||||
|
BLog.LOGE("DC_LI >>>> desc >>>> ${desc}")
|
||||||
|
BLog.LOGE("DC_LI >>>> dateTiem >>>> ${dateTiem}")
|
||||||
|
if (title.length > 0 && link.length > 0) {
|
||||||
|
DcInside().apply {
|
||||||
|
this.link = link
|
||||||
|
this.title = title
|
||||||
|
this.thumbnail = thumbnail
|
||||||
|
this.desc = desc
|
||||||
|
this.dateTiem = dateTiem
|
||||||
|
}.apply {
|
||||||
|
temp.add(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return temp
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user