Advertisement
Guest User

Untitled

a guest
Feb 14th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #r "MySql.Data"
  2. #r "Html2Markdown"
  3. #r "NPoco"
  4. //#r "ReverseMarkdown" //this one turned <li> into "-" vs "*"
  5. //install these libs via scriptcs -install libname
  6.  
  7. using NPoco;
  8.  
  9. public class Post {
  10. public double id {get; private set;}
  11. public string post_content {get; private set;}
  12. }
  13.  
  14. var cxnString = "Server=xxx;Database=xxx;User=xxx;Password=xxx;";
  15. var database = new Database(cxnString, DatabaseType.MySQL, MySql.Data.MySqlClient.MySqlClientFactory.Instance);
  16.  
  17. var query = $@"select
  18. id,
  19. post_title,
  20. post_content,
  21. post_content_filtered
  22. from wp_posts as parent
  23. where post_type = 'post'
  24. and post_parent = 0
  25. /*and post_content_filtered = ''*/
  26. and id in ('{Environment.GetCommandLineArgs()[3]}')
  27. ;";
  28.  
  29. var cxn = new MySql.Data.MySqlClient.MySqlConnection(cxnString);
  30. var savecmd = cxn.CreateCommand();
  31. cxn.Open();
  32.  
  33. var posts = database.Fetch<Post>(query);
  34.  
  35. var converter = new Html2Markdown.Converter();
  36.  
  37. foreach(var post in posts) {
  38. savecmd.CommandText = $"update wp_posts set post_content_filtered = '{converter.Convert(post.post_content).Replace("'", "''")}' where id = {post.id}";
  39. savecmd.ExecuteNonQuery();
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement