Skip to content

Instantly share code, notes, and snippets.

@kingori
Last active August 29, 2015 14:10
Show Gist options
  • Save kingori/98420b577f082f7fc021 to your computer and use it in GitHub Desktop.
Save kingori/98420b577f082f7fc021 to your computer and use it in GitHub Desktop.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kr.pe.kingori.silgeupgum">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:protectionLevel="signature"
android:name="kr.pe.kingori.silgeupgum.permission.C2D_MESSAGE" />
<uses-permission android:name="kr.pe.kingori.silgeupgum.permission.C2D_MESSAGE" />
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="kr.pe.kingori.silgeupgum.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="kr.pe.kingori.silgeupgum" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="@drawable/ic_launcher" />
...
</application>
</manifest>
package kr.pe.kingori.silgeupgum;
import com.bumptech.glide.Glide;
import com.bumptech.glide.integration.okhttp.OkHttpUrlLoader;
import com.bumptech.glide.load.model.GlideUrl;
import com.parse.Parse;
import java.io.InputStream;
import kr.pe.kingori.silgeupgum.io.Api;
public class Application extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
Glide.get(this).register(GlideUrl.class, InputStream.class,
new OkHttpUrlLoader.Factory(Api.client));
Parse.initialize(this, getString(R.string.parse_application_id),
getString(R.string.parse_client_key));
}
}
<html>
<head>
<script type="text/javascript">
var titleArg = unescape(decodeURI(/title=(.*)/.exec(document.location.href)[1]).replace(/\+/g, ' '));
var disqus_shortname = 'your_site_shortname'; // required: replace example with your forum shortname
var disqus_identifier = titleArg;
</script>
</head>
<body >
<div height="60">
<h1 id="title" align="center"></h1>
</div>
<div id="disqus_thread"></div>
<script type="text/javascript">
document.getElementById('title').innerText = titleArg;
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</body>
</html>
function fetchData() {
var items = getCurrentSilGeupGum();
writeToSheet(items);
writeToJson();
}
function getCurrentSilGeupGum() {
var html = UrlFetchApp.fetch("http://www.daum.net", {
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
...
}
}).getContentText();
//... 별로 중요한 거 아니니...
var html = doc.getRootElement();
var li = html.getChildren('li');
var items = new Array();
for( var i=0;i<li.length;i++) {
title= ...;
url = ...;
imageUrl = fetchImageUrl(title);
items.push( { 'title':title.trim(), 'url':url.trim(),'image_url':imageUrl } )
}
return items;
}
function writeToSheet(items) {
var ss = SpreadsheetApp.getActive();
var curSheet = ss.getActiveSheet();
var rowNum = 1;
var curTime = new Date();
var curTimeEpoch = curTime.getTime();
curSheet.insertRows(2, items.length);
var valueArray = new Array(items.length);
for( var i =0;i<items.length;i++) {
values= new Array(6);
var item = items[i];
values[0] = curTime.toISOString();
//별로 안중요...
values[5] = item.image_url;
valueArray[i]= values;
}
curSheet.getRange(2, 1, items.length, 6).setValues(valueArray);
var deleteStartRow = 242; // 10 * 24 + 2;
var maxRow = curSheet.getLastRow();
if( maxRow >= 242 ) {
curSheet.deleteRows(242, maxRow - 242 + 1);
}
}
function writeToJson() {
var ss = SpreadsheetApp.getActive();
var curSheet = ss.getActiveSheet();
var jsonResult = new Object();
jsonResult.hours = new Array();
var hourItem = null;
var lastTime= '';
var values = curSheet.getRange(2,2, curSheet.getLastRow() -2+1, 5 ).getValues();
for( var i=0; i < values.length;i++) {
var time = values[i][0];
//...
hourItem.items.push( makeItem( values[i] ) );
}
jsonResult.hours.push( hourItem );
var folder = DriveApp.getFoldersByName(out_json_folder_name).next();
var prevFiles = folder.getFilesByName(out_json_file_name);
if (prevFiles.hasNext()) {
prevFiles.next().setContent( JSON.stringify(jsonResult) );
} else {
folder.createFile( out_json_file_name, JSON.stringify(jsonResult) ,"application/json" );
}
}
function sendParsePush() {
var payload =
'{"where" : {"push_mode":"MORNING_NIGHT"}, "data" : {"alert":"오늘의 검색어를 확인해보세요!"}}';
var pushParams = {
'method':'post',
'payload' : payload,
'headers' : {
'X-Parse-Application-Id': '**parse_app_id**',
'X-Parse-REST-API-Key': '**parse_rest_api_key**',
},
'contentType':'application/json'
};
UrlFetchApp.fetch("https://api.parse.com/1/push", pushParams);
}
package kr.pe.kingori.silgeupgum;
import android.content.Context;
import android.content.Intent;
import kr.pe.kingori.silgeupgum.ui.activity.MainActivity;
public class ParsePushBroadcastReceiver extends com.parse.ParsePushBroadcastReceiver {
@Override
protected void onPushOpen(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.putExtra(MainActivity.EXTRA_RELOAD, true);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(i);
}
}
public abstract class Utils {
public static enum PushMode {
NONE, MORNING_NIGHT
}
public static PushMode getPushMode(Context context) {
if (pushMode == null) {
pushMode = PushMode.valueOf(
getSharedPreferences(context).getString(KEY_PUSH_MODE, PushMode.NONE.name()));
}
if (pushMode == null) {
pushMode = PushMode.NONE;
}
return pushMode;
}
public static void updatePushMode(Context context, PushMode pushMode) {
Utils.pushMode = pushMode;
getSharedPreferences(context).edit().putString(KEY_PUSH_MODE, pushMode.name()).commit();
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put(KEY_PUSH_MODE, pushMode.name());
installation.saveInBackground();
}
private static SharedPreferences getSharedPreferences(Context context) {
return context.getSharedPreferences(SF_NAME, Context.MODE_PRIVATE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment